MCPcopy Index your code
hub / github.com/bpython/bpython / safe_getitem

Function safe_getitem

bpython/simpleeval.py:181–188  ·  view source on GitHub ↗

Safely tries to access obj[index]

(obj, index)

Source from the content-addressed store, hash-verified

179
180
181def safe_getitem(obj, index):
182 """Safely tries to access obj[index]"""
183 if type(obj) in (list, tuple, dict, bytes, str):
184 try:
185 return obj[index]
186 except (KeyError, IndexError):
187 raise EvaluationError(f"can't lookup key {index!r} on {obj!r}")
188 raise ValueError(f"unsafe to lookup on object of type {type(obj)}")
189
190
191def find_attribute_with_name(node, name):

Callers 1

_convertFunction · 0.85

Calls 1

EvaluationErrorClass · 0.85

Tested by

no test coverage detected