@@ -1742,13 +1742,25 @@ def process_imported_symbol(self,
1742
1742
fullname : str ,
1743
1743
context : ImportBase ) -> None :
1744
1744
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
+
1745
1754
if isinstance (node .node , PlaceholderNode ):
1746
1755
if self .final_iteration :
1747
1756
self .report_missing_module_attribute (module_id , id , imported_id , context )
1748
1757
return
1749
1758
else :
1750
1759
# 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 )
1752
1764
existing_symbol = self .globals .get (imported_id )
1753
1765
if (existing_symbol and not isinstance (existing_symbol .node , PlaceholderNode ) and
1754
1766
not isinstance (node .node , PlaceholderNode )):
@@ -1760,14 +1772,6 @@ def process_imported_symbol(self,
1760
1772
# Imports are special, some redefinitions are allowed, so wait until
1761
1773
# we know what is the new symbol node.
1762
1774
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
1771
1775
# NOTE: we take the original node even for final `Var`s. This is to support
1772
1776
# a common pattern when constants are re-exported (same applies to import *).
1773
1777
self .add_imported_symbol (imported_id , node , context ,
@@ -1866,6 +1870,7 @@ def visit_import_all(self, i: ImportAll) -> None:
1866
1870
self .add_imported_symbol (name , node , i ,
1867
1871
module_public = module_public ,
1868
1872
module_hidden = not module_public )
1873
+
1869
1874
else :
1870
1875
# Don't add any dummy symbols for 'from x import *' if 'x' is unknown.
1871
1876
pass
@@ -4338,6 +4343,7 @@ def add_imported_symbol(self,
4338
4343
module_public : bool = True ,
4339
4344
module_hidden : bool = False ) -> None :
4340
4345
"""Add an alias to an existing symbol through import."""
4346
+ assert not module_hidden or not module_public
4341
4347
symbol = SymbolTableNode (node .kind , node .node ,
4342
4348
module_public = module_public ,
4343
4349
module_hidden = module_hidden )
@@ -4421,7 +4427,9 @@ def record_incomplete_ref(self) -> None:
4421
4427
self .num_incomplete_refs += 1
4422
4428
4423
4429
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 :
4425
4433
"""Mark a definition as incomplete (and defer current analysis target).
4426
4434
4427
4435
Also potentially mark the current namespace as incomplete.
@@ -4440,7 +4448,9 @@ def mark_incomplete(self, name: str, node: Node,
4440
4448
assert self .statement
4441
4449
placeholder = PlaceholderNode (fullname , node , self .statement .line ,
4442
4450
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 ())
4444
4454
self .missing_names .add (name )
4445
4455
4446
4456
def is_incomplete_namespace (self , fullname : str ) -> bool :
0 commit comments