MCPcopy Index your code
hub / github.com/ipython/ipython / can_get_item

Method can_get_item

IPython/core/guarded_eval.py:310–326  ·  view source on GitHub ↗

Allow accessing `__getiitem__` of allow-listed instances unless it was not modified.

(self, value, item)

Source from the content-addressed store, hash-verified

308 return False
309
310 def can_get_item(self, value, item):
311 """Allow accessing `__getiitem__` of allow-listed instances unless it was not modified."""
312 allowed_getitem_external = _coerce_path_to_tuples(self.allowed_getitem_external)
313 if self.allow_getitem_on_types:
314 # e.g. Union[str, int] or Literal[True, 1]
315 if isinstance(value, (typing._SpecialForm, typing._BaseGenericAlias)):
316 return True
317 # PEP 560 e.g. list[str]
318 if isinstance(value, type) and hasattr(value, "__class_getitem__"):
319 return True
320 return _has_original_dunder(
321 value,
322 allowed_types=self.allowed_getitem,
323 allowed_methods=self._getitem_methods,
324 allowed_external=allowed_getitem_external,
325 method_name="__getitem__",
326 )
327
328 def can_operate(self, dunders: tuple[str, ...], a, b=None):
329 allowed_operations_external = _coerce_path_to_tuples(

Callers 2

_handle_assignFunction · 0.45
eval_nodeFunction · 0.45

Calls 2

_coerce_path_to_tuplesFunction · 0.85
_has_original_dunderFunction · 0.85

Tested by

no test coverage detected