Safely tries to access obj[index]
(obj, index)
| 179 | |
| 180 | |
| 181 | def 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 | |
| 191 | def find_attribute_with_name(node, name): |
no test coverage detected