Safely evaluates the expression having an attributed accessed
(cursor_offset, line, namespace=None)
| 244 | |
| 245 | |
| 246 | def evaluate_current_attribute(cursor_offset, line, namespace=None): |
| 247 | """Safely evaluates the expression having an attributed accessed""" |
| 248 | # this function runs user code in case of custom descriptors, |
| 249 | # so could fail in any way |
| 250 | |
| 251 | obj = evaluate_current_expression(cursor_offset, line, namespace) |
| 252 | attr = line_properties.current_expression_attribute(cursor_offset, line) |
| 253 | if attr is None: |
| 254 | raise EvaluationError("No attribute found to look up") |
| 255 | try: |
| 256 | return getattr(obj, attr.word) |
| 257 | except AttributeError: |
| 258 | raise EvaluationError(f"can't lookup attribute {attr.word} on {obj!r}") |
nothing calls this directly
no test coverage detected