Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -1731,8 +1731,15 @@ def visit_import_from(self, imp: ImportFrom) -> None:
# Target module exists but the imported name is missing or hidden.
self.report_missing_module_attribute(module_id, id, imported_id, imp)
else:
module_public = (
not self.is_stub_file
and self.options.implicit_reexport
or as_id is not None
)
# Import of a missing (sub)module.
self.add_unknown_imported_symbol(imported_id, imp, target_name=fullname)
self.add_unknown_imported_symbol(
imported_id, imp, target_name=fullname, module_public=module_public
)

def process_imported_symbol(self,
node: SymbolTableNode,
Expand Down Expand Up @@ -4327,7 +4334,9 @@ def add_module_symbol(self,
module_public=module_public,
module_hidden=module_hidden)
else:
self.add_unknown_imported_symbol(as_id, context, target_name=id)
self.add_unknown_imported_symbol(
as_id, context, target_name=id, module_public=module_public
)

def add_local(self, node: Union[Var, FuncDef, OverloadedFuncDef], context: Context) -> None:
"""Add local variable or function."""
Expand All @@ -4352,7 +4361,8 @@ def add_imported_symbol(self,
def add_unknown_imported_symbol(self,
name: str,
context: Context,
target_name: Optional[str] = None) -> None:
target_name: Optional[str] = None,
module_public: bool = True) -> None:
"""Add symbol that we don't know what it points to because resolving an import failed.

This can happen if a module is missing, or it is present, but doesn't have
Expand Down Expand Up @@ -4380,7 +4390,7 @@ def add_unknown_imported_symbol(self,
any_type = AnyType(TypeOfAny.from_unimported_type, missing_import_name=var._fullname)
var.type = any_type
var.is_suppressed_import = True
self.add_symbol(name, var, context)
self.add_symbol(name, var, context, module_public=module_public)

#
# Other helpers
Expand Down
2 changes: 2 additions & 0 deletions mypy/test/teststubtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ def h(x: str): ...
yield Case("", "__all__ = []", None) # dummy case
yield Case(stub="", runtime="__all__ += ['y']\ny = 5", error="y")
yield Case(stub="", runtime="__all__ += ['g']\ndef g(): pass", error="g")
# Here we should only check that runtime has B, since the stub explicitly re-exports it
yield Case(stub="from mystery import A, B as B # type: ignore", runtime="", error="B")

@collect_cases
def test_name_mangling(self) -> Iterator[Case]:
Expand Down