@@ -42,23 +42,27 @@ def process_newtype_declaration(self, s: AssignmentStmt) -> bool:
4242 The logic in this function mostly copies the logic for visit_class_def()
4343 with a single (non-Generic) base.
4444 """
45- name , call = self .analyze_newtype_declaration (s )
46- if name is None or call is None :
45+ var_name , call = self .analyze_newtype_declaration (s )
46+ if var_name is None or call is None :
4747 return False
48+ name = var_name
4849 # OK, now we know this is a NewType. But the base type may be not ready yet,
4950 # add placeholder as we do for ClassDef.
5051
52+ if self .api .is_func_scope ():
53+ name += '@' + str (s .line )
5154 fullname = self .api .qualified_name (name )
55+
5256 if (not call .analyzed or
5357 isinstance (call .analyzed , NewTypeExpr ) and not call .analyzed .info ):
5458 # Start from labeling this as a future class, as we do for normal ClassDefs.
5559 placeholder = PlaceholderNode (fullname , s , s .line , becomes_typeinfo = True )
56- self .api .add_symbol (name , placeholder , s , can_defer = False )
60+ self .api .add_symbol (var_name , placeholder , s , can_defer = False )
5761
58- old_type , should_defer = self .check_newtype_args (name , call , s )
62+ old_type , should_defer = self .check_newtype_args (var_name , call , s )
5963 old_type = get_proper_type (old_type )
6064 if not call .analyzed :
61- call .analyzed = NewTypeExpr (name , old_type , line = call .line , column = call .column )
65+ call .analyzed = NewTypeExpr (var_name , old_type , line = call .line , column = call .column )
6266 if old_type is None :
6367 if should_defer :
6468 # Base type is not ready.
@@ -98,7 +102,9 @@ def process_newtype_declaration(self, s: AssignmentStmt) -> bool:
98102 call .analyzed .info = newtype_class_info
99103 else :
100104 call .analyzed .info .bases = newtype_class_info .bases
101- self .api .add_symbol (name , call .analyzed .info , s )
105+ self .api .add_symbol (var_name , call .analyzed .info , s )
106+ if self .api .is_func_scope ():
107+ self .api .add_symbol_skip_local (name , call .analyzed .info )
102108 newtype_class_info .line = s .line
103109 return True
104110
@@ -191,7 +197,7 @@ def build_newtype_typeinfo(self, name: str, old_type: Type, base_type: Instance)
191197 name = name )
192198 init_func = FuncDef ('__init__' , args , Block ([]), typ = signature )
193199 init_func .info = info
194- init_func ._fullname = self . api . qualified_name ( name ) + '.__init__'
200+ init_func ._fullname = info . fullname + '.__init__'
195201 info .names ['__init__' ] = SymbolTableNode (MDEF , init_func )
196202
197203 return info
0 commit comments