@@ -425,7 +425,7 @@ class TypeChecker(NodeVisitor[None], TypeCheckerSharedApi, SplittingVisitor):
425425 # NOTE: The names might not be unique, they are only for debugging purposes.
426426 widened_vars : list [str ]
427427 # Global variables widened inside a function body, to be propagated to
428- # the module-level binder after the function is type checked.
428+ # the module-level binder after the function is type checked (with --allow-redefinition-new) .
429429 _globals_widened_in_func : list [tuple [NameExpr , Type ]]
430430 globals : SymbolTable
431431 modules : dict [str , MypyFile ]
@@ -4964,7 +4964,7 @@ def can_widen_in_scope(self, name: NameExpr, orig_type: Type) -> bool:
49644964 """Can a variable type be widened via assignment in the current scope?
49654965
49664966 Globals can only be widened from within a function if the original type
4967- is None (backward compat with partial type handling of `` x = None` `).
4967+ is None (backward compat with partial type handling of `x = None`).
49684968 """
49694969 if (
49704970 name .kind == GDEF
@@ -8372,6 +8372,7 @@ def visit_nonlocal_decl(self, o: NonlocalDecl, /) -> None:
83728372
83738373 def visit_global_decl (self , o : GlobalDecl , / ) -> None :
83748374 if self .options .allow_redefinition_new :
8375+ # Add names to binder, since their types could be widened
83758376 for name in o .names :
83768377 sym = self .globals .get (name )
83778378 if sym and isinstance (sym .node , Var ) and sym .node .type is not None :
0 commit comments