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

Function evaluate_current_attribute

bpython/simpleeval.py:246–258  ·  view source on GitHub ↗

Safely evaluates the expression having an attributed accessed

(cursor_offset, line, namespace=None)

Source from the content-addressed store, hash-verified

244
245
246def 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}")

Callers

nothing calls this directly

Calls 2

EvaluationErrorClass · 0.85

Tested by

no test coverage detected