Iterate over local definitions (not imported) in a symbol table. Recursively iterate over class members and nested classes. If impl_only is True, do not yield the classes themselves, only methods.
(
names: SymbolTable, name_prefix: str, info: TypeInfo | None = None, impl_only: bool = False
)
| 5337 | |
| 5338 | |
| 5339 | def local_definitions( |
| 5340 | names: SymbolTable, name_prefix: str, info: TypeInfo | None = None, impl_only: bool = False |
| 5341 | ) -> Iterator[Definition]: |
| 5342 | """Iterate over local definitions (not imported) in a symbol table. |
| 5343 | |
| 5344 | Recursively iterate over class members and nested classes. If impl_only is True, do |
| 5345 | not yield the classes themselves, only methods. |
| 5346 | """ |
| 5347 | # TODO: What should the name be? Or maybe remove it? |
| 5348 | for name, symnode in names.items(): |
| 5349 | shortname = name |
| 5350 | if "-redef" in name: |
| 5351 | # Restore original name from mangled name of multiply defined function |
| 5352 | shortname = name.split("-redef")[0] |
| 5353 | fullname = name_prefix + "." + shortname |
| 5354 | node = symnode.node |
| 5355 | if node and node.fullname == fullname: |
| 5356 | yield_node = True |
| 5357 | if impl_only: |
| 5358 | if not isinstance(node, (FuncDef, OverloadedFuncDef, Decorator)): |
| 5359 | yield_node = False |
| 5360 | else: |
| 5361 | impl = node.func if isinstance(node, Decorator) else node |
| 5362 | yield_node = not impl.def_or_infer_vars |
| 5363 | # This logic for plugin generated nodes preserves historical behavior. |
| 5364 | # On one hand, we generally type-check plugin generated nodes, since |
| 5365 | # some 3rd party plugins may rely on this behavior. On the other hand |
| 5366 | # we skip nodes generated by mypy itself, these nodes are not added to |
| 5367 | # the class AST (only to symbol table) as they often cut corners. |
| 5368 | if symnode.plugin_generated and info and node not in info.defn.defs.body: |
| 5369 | yield_node = False |
| 5370 | if isinstance(node, (FuncDef, OverloadedFuncDef, Decorator)) and "@" in fullname: |
| 5371 | yield_node = False |
| 5372 | if yield_node: |
| 5373 | yield fullname, symnode, info |
| 5374 | if isinstance(node, TypeInfo): |
| 5375 | yield from local_definitions(node.names, fullname, node, impl_only) |
| 5376 | |
| 5377 | |
| 5378 | def set_info(node: SymbolNode, info: TypeInfo) -> None: |
no test coverage detected
searching dependent graphs…