1
0
forked from VimPlug/jedi

Allow unsafe custom __getitem__ executions when allow unsafe executions is on

This commit is contained in:
Dave Halter
2023-07-29 00:33:09 +02:00
parent 8a4b079d0f
commit 57aefed6ea
3 changed files with 25 additions and 5 deletions

View File

@@ -230,8 +230,8 @@ class DirectObjectAccess:
return [annotation]
return None
def py__simple_getitem__(self, index):
if type(self._obj) not in ALLOWED_GETITEM_TYPES:
def py__simple_getitem__(self, index, *, safe=True):
if safe and type(self._obj) not in ALLOWED_GETITEM_TYPES:
# Get rid of side effects, we won't call custom `__getitem__`s.
return None

View File

@@ -162,7 +162,10 @@ class CompiledValue(Value):
def py__simple_getitem__(self, index):
with reraise_getitem_errors(IndexError, KeyError, TypeError):
try:
access = self.access_handle.py__simple_getitem__(index)
access = self.access_handle.py__simple_getitem__(
index,
safe=not self.inference_state.allow_unsafe_executions
)
except AttributeError:
return super().py__simple_getitem__(index)
if access is None: