Skip to content

Commit e83f4fd

Browse files
authored
Ammed the refactoring of add_unknown_symbol() (#6456)
1 parent e42e45d commit e83f4fd

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

mypy/newsemanal/semanal.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1659,7 +1659,7 @@ def visit_import_from(self, imp: ImportFrom) -> None:
16591659
else:
16601660
# Missing module.
16611661
missing_name = import_id + '.' + id
1662-
self.add_unknown_symbol(imported_id, imp, target_name=missing_name)
1662+
self.add_unknown_imported_symbol(imported_id, imp, target_name=missing_name)
16631663

16641664
def report_missing_module_attribute(self, import_id: str, source_id: str, imported_id: str,
16651665
context: Node) -> None:
@@ -1674,7 +1674,7 @@ def report_missing_module_attribute(self, import_id: str, source_id: str, import
16741674
if extra:
16751675
message += " {}".format(extra)
16761676
self.fail(message, context)
1677-
self.add_unknown_symbol(imported_id, context)
1677+
self.add_unknown_imported_symbol(imported_id, context)
16781678

16791679
if import_id == 'typing':
16801680
# The user probably has a missing definition in a test fixture. Let's verify.
@@ -4045,7 +4045,7 @@ def add_module_symbol(self, id: str, as_id: str, module_public: bool,
40454045
module_public=module_public,
40464046
module_hidden=module_hidden)
40474047
else:
4048-
self.add_unknown_symbol(as_id, context, target_name=id)
4048+
self.add_unknown_imported_symbol(as_id, context, target_name=id)
40494049

40504050
def add_local(self, node: Union[Var, FuncDef, OverloadedFuncDef], context: Context) -> None:
40514051
"""Add local variable or function."""
@@ -4062,9 +4062,15 @@ def add_imported_symbol(self, name: str, node: SymbolTableNode, context: Context
40624062
module_hidden=module_hidden)
40634063
self.add_symbol_table_node(name, symbol, context)
40644064

4065-
def add_unknown_symbol(self, name: str, context: Context,
4066-
target_name: Optional[str] = None) -> None:
4067-
"""Add symbol that we don't know what it points to (due to error, for example)."""
4065+
def add_unknown_imported_symbol(self, name: str, context: Context,
4066+
target_name: Optional[str] = None) -> None:
4067+
"""Add symbol that we don't know what it points to because resolving an import failed.
4068+
4069+
This can happen if a module is missing, or it is present, but doesn't have
4070+
the imported attribute. The `target_name` is the name of symbol in the namespace
4071+
it is imported from. For example, for 'from mod import x as y' the target_name is
4072+
'mod.x'. This is currently used only to track logical dependencies.
4073+
"""
40684074
existing = self.current_symbol_table().get(name)
40694075
if existing and isinstance(existing.node, Var) and existing.node.is_suppressed_import:
40704076
# This missing import was already added -- nothing to do here.

0 commit comments

Comments
 (0)