MCPcopy Index your code
hub / github.com/python/mypy / expression_def

Method expression_def

mypy/inspections.py:429–459  ·  view source on GitHub ↗

Find and format definition location for an expression. If it is not a RefExpr, it is effectively skipped by returning an empty result.

(self, expression: Expression)

Source from the content-addressed store, hash-verified

427 return modules, reload_needed
428
429 def expression_def(self, expression: Expression) -> tuple[str, bool]:
430 """Find and format definition location for an expression.
431
432 If it is not a RefExpr, it is effectively skipped by returning an
433 empty result.
434 """
435 if not isinstance(expression, RefExpr):
436 # If there are no suitable matches at all, we return error later.
437 return "", True
438
439 nodes = self.collect_nodes(expression)
440
441 if not nodes:
442 return self.missing_node(expression), False
443
444 modules, reload_needed = self.modules_for_nodes(nodes, expression)
445 if reload_needed:
446 # TODO: line/column are not stored in cache for vast majority of symbol nodes.
447 # Adding them will make thing faster, but will have visible memory impact.
448 nodes = self.collect_nodes(expression)
449 modules, reload_needed = self.modules_for_nodes(nodes, expression)
450 assert not reload_needed
451
452 result = []
453 for node in modules:
454 result.append(self.format_node(modules[node], node))
455
456 if not result:
457 return self.missing_node(expression), False
458
459 return self.add_prefixes(", ".join(result), expression), True
460
461 def missing_type(self, expression: Expression) -> str:
462 alt_suggestion = ""

Callers

nothing calls this directly

Calls 8

collect_nodesMethod · 0.95
missing_nodeMethod · 0.95
modules_for_nodesMethod · 0.95
format_nodeMethod · 0.95
add_prefixesMethod · 0.95
isinstanceFunction · 0.85
appendMethod · 0.80
joinMethod · 0.45

Tested by

no test coverage detected