@@ -615,9 +615,12 @@ def refresh_top_level(self, file_node: MypyFile) -> None:
615
615
616
616
def add_implicit_module_attrs (self , file_node : MypyFile ) -> None :
617
617
"""Manually add implicit definitions of module '__name__' etc."""
618
+ str_type : Type | None = self .named_type_or_none ("builtins.str" )
619
+ if str_type is None :
620
+ str_type = UnboundType ("builtins.str" )
618
621
for name , t in implicit_module_attrs .items ():
619
622
if name == "__doc__" :
620
- typ : Type = UnboundType ( "__builtins__.str" )
623
+ typ : Type = str_type
621
624
elif name == "__path__" :
622
625
if not file_node .is_package_init_file ():
623
626
continue
@@ -630,7 +633,7 @@ def add_implicit_module_attrs(self, file_node: MypyFile) -> None:
630
633
if not isinstance (node , TypeInfo ):
631
634
self .defer (node )
632
635
return
633
- typ = Instance (node , [self . str_type () ])
636
+ typ = Instance (node , [str_type ])
634
637
elif name == "__annotations__" :
635
638
sym = self .lookup_qualified ("__builtins__.dict" , Context (), suppress_errors = True )
636
639
if not sym :
@@ -639,7 +642,7 @@ def add_implicit_module_attrs(self, file_node: MypyFile) -> None:
639
642
if not isinstance (node , TypeInfo ):
640
643
self .defer (node )
641
644
return
642
- typ = Instance (node , [self . str_type () , AnyType (TypeOfAny .special_form )])
645
+ typ = Instance (node , [str_type , AnyType (TypeOfAny .special_form )])
643
646
else :
644
647
assert t is not None , f"type should be specified for { name } "
645
648
typ = UnboundType (t )
0 commit comments