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

Method _evaluate_expr

IPython/core/completer.py:1363–1396  ·  view source on GitHub ↗
(self, expr)

Source from the content-addressed store, hash-verified

1361 return ""
1362
1363 def _evaluate_expr(self, expr):
1364 obj = not_found
1365 done = False
1366 while not done and expr:
1367 try:
1368 obj = guarded_eval(
1369 expr,
1370 EvaluationContext(
1371 globals=self.global_namespace,
1372 locals=self.namespace,
1373 evaluation=self.evaluation,
1374 auto_import=self._auto_import,
1375 policy_overrides=self.policy_overrides,
1376 ),
1377 )
1378 done = True
1379 except (SyntaxError, TypeError) as e:
1380 if self.debug:
1381 warnings.warn(f"Trimming because of {e}")
1382 # TypeError can show up with something like `+ d`
1383 # where `d` is a dictionary.
1384
1385 # trim the expression to remove any invalid prefix
1386 # e.g. user starts `(d[`, so we get `expr = '(d'`,
1387 # where parenthesis is not closed.
1388 # TODO: make this faster by reusing parts of the computation?
1389 expr = self._trim_expr(expr)
1390 except Exception as e:
1391 if self.debug:
1392 warnings.warn(f"Evaluation exception {e}")
1393 done = True
1394 if self.debug:
1395 warnings.warn(f"Resolved to {obj}")
1396 return obj
1397
1398 @property
1399 def _auto_import(self):

Callers 2

_attr_matchesMethod · 0.95
dict_key_matchesMethod · 0.80

Calls 4

_trim_exprMethod · 0.95
guarded_evalFunction · 0.90
EvaluationContextClass · 0.90
warnMethod · 0.80

Tested by

no test coverage detected