@@ -1742,13 +1742,25 @@ def process_imported_symbol(self,
17421742 fullname : str ,
17431743 context : ImportBase ) -> None :
17441744 imported_id = as_id or id
1745+ # 'from m import x as x' exports x in a stub file or when implicit
1746+ # re-exports are disabled.
1747+ module_public = (
1748+ not self .is_stub_file
1749+ and self .options .implicit_reexport
1750+ or as_id is not None
1751+ )
1752+ module_hidden = not module_public and fullname not in self .modules
1753+
17451754 if isinstance (node .node , PlaceholderNode ):
17461755 if self .final_iteration :
17471756 self .report_missing_module_attribute (module_id , id , imported_id , context )
17481757 return
17491758 else :
17501759 # This might become a type.
1751- self .mark_incomplete (imported_id , node .node , becomes_typeinfo = True )
1760+ self .mark_incomplete (imported_id , node .node ,
1761+ module_public = module_public ,
1762+ module_hidden = module_hidden ,
1763+ becomes_typeinfo = True )
17521764 existing_symbol = self .globals .get (imported_id )
17531765 if (existing_symbol and not isinstance (existing_symbol .node , PlaceholderNode ) and
17541766 not isinstance (node .node , PlaceholderNode )):
@@ -1760,14 +1772,6 @@ def process_imported_symbol(self,
17601772 # Imports are special, some redefinitions are allowed, so wait until
17611773 # we know what is the new symbol node.
17621774 return
1763- # 'from m import x as x' exports x in a stub file or when implicit
1764- # re-exports are disabled.
1765- module_public = (
1766- not self .is_stub_file
1767- and self .options .implicit_reexport
1768- or as_id is not None
1769- )
1770- module_hidden = not module_public and fullname not in self .modules
17711775 # NOTE: we take the original node even for final `Var`s. This is to support
17721776 # a common pattern when constants are re-exported (same applies to import *).
17731777 self .add_imported_symbol (imported_id , node , context ,
@@ -1866,6 +1870,7 @@ def visit_import_all(self, i: ImportAll) -> None:
18661870 self .add_imported_symbol (name , node , i ,
18671871 module_public = module_public ,
18681872 module_hidden = not module_public )
1873+
18691874 else :
18701875 # Don't add any dummy symbols for 'from x import *' if 'x' is unknown.
18711876 pass
@@ -4338,6 +4343,7 @@ def add_imported_symbol(self,
43384343 module_public : bool = True ,
43394344 module_hidden : bool = False ) -> None :
43404345 """Add an alias to an existing symbol through import."""
4346+ assert not module_hidden or not module_public
43414347 symbol = SymbolTableNode (node .kind , node .node ,
43424348 module_public = module_public ,
43434349 module_hidden = module_hidden )
@@ -4421,7 +4427,9 @@ def record_incomplete_ref(self) -> None:
44214427 self .num_incomplete_refs += 1
44224428
44234429 def mark_incomplete (self , name : str , node : Node ,
4424- becomes_typeinfo : bool = False ) -> None :
4430+ becomes_typeinfo : bool = False ,
4431+ module_public : bool = True ,
4432+ module_hidden : bool = False ) -> None :
44254433 """Mark a definition as incomplete (and defer current analysis target).
44264434
44274435 Also potentially mark the current namespace as incomplete.
@@ -4440,7 +4448,9 @@ def mark_incomplete(self, name: str, node: Node,
44404448 assert self .statement
44414449 placeholder = PlaceholderNode (fullname , node , self .statement .line ,
44424450 becomes_typeinfo = becomes_typeinfo )
4443- self .add_symbol (name , placeholder , context = dummy_context ())
4451+ self .add_symbol (name , placeholder ,
4452+ module_public = module_public , module_hidden = module_hidden ,
4453+ context = dummy_context ())
44444454 self .missing_names .add (name )
44454455
44464456 def is_incomplete_namespace (self , fullname : str ) -> bool :
0 commit comments