@@ -355,11 +355,7 @@ def _expand_once(self) -> Type:
355355 ):
356356 mapping [tvar .id ] = sub
357357
358- new_tp = self .alias .target .accept (InstantiateAliasVisitor (mapping ))
359- new_tp .accept (LocationSetter (self .line , self .column ))
360- new_tp .line = self .line
361- new_tp .column = self .column
362- return new_tp
358+ return self .alias .target .accept (InstantiateAliasVisitor (mapping ))
363359
364360 def _partial_expansion (self , nothing_args : bool = False ) -> tuple [ProperType , bool ]:
365361 # Private method mostly for debugging and testing.
@@ -3260,7 +3256,6 @@ def get_proper_types(
32603256 TypeTranslator as TypeTranslator ,
32613257 TypeVisitor as TypeVisitor ,
32623258)
3263- from mypy .typetraverser import TypeTraverserVisitor
32643259
32653260
32663261class TypeStrVisitor (SyntheticTypeVisitor [str ]):
@@ -3598,23 +3593,6 @@ def is_named_instance(t: Type, fullnames: str | tuple[str, ...]) -> TypeGuard[In
35983593 return isinstance (t , Instance ) and t .type .fullname in fullnames
35993594
36003595
3601- class LocationSetter (TypeTraverserVisitor ):
3602- # TODO: Should we update locations of other Type subclasses?
3603- def __init__ (self , line : int , column : int ) -> None :
3604- self .line = line
3605- self .column = column
3606-
3607- def visit_instance (self , typ : Instance ) -> None :
3608- typ .line = self .line
3609- typ .column = self .column
3610- super ().visit_instance (typ )
3611-
3612- def visit_type_alias_type (self , typ : TypeAliasType ) -> None :
3613- typ .line = self .line
3614- typ .column = self .column
3615- super ().visit_type_alias_type (typ )
3616-
3617-
36183596class HasTypeVars (BoolTypeQuery ):
36193597 """Visitor for querying whether a type has a type variable component."""
36203598
@@ -3709,8 +3687,8 @@ def flatten_nested_unions(
37093687
37103688 flat_items : list [Type ] = []
37113689 for t in typelist :
3712- if handle_type_alias_type :
3713- if not handle_recursive and isinstance ( t , TypeAliasType ) and t .is_recursive :
3690+ if handle_type_alias_type and isinstance ( t , TypeAliasType ) :
3691+ if not handle_recursive and t .is_recursive :
37143692 tp : Type = t
37153693 else :
37163694 tp = get_proper_type (t )
@@ -3757,7 +3735,21 @@ def flatten_nested_tuples(types: Iterable[Type]) -> list[Type]:
37573735 if not isinstance (p_type , TupleType ):
37583736 res .append (typ )
37593737 continue
3760- res .extend (flatten_nested_tuples (p_type .items ))
3738+ if isinstance (typ .type , TypeAliasType ):
3739+ items = []
3740+ for item in p_type .items :
3741+ if (
3742+ isinstance (item , ProperType )
3743+ and isinstance (item , Instance )
3744+ or isinstance (item , TypeAliasType )
3745+ ):
3746+ if len (item .args ) == 0 :
3747+ item = item .copy_modified ()
3748+ item .set_line (typ )
3749+ items .append (item )
3750+ else :
3751+ items = p_type .items
3752+ res .extend (flatten_nested_tuples (items ))
37613753 return res
37623754
37633755
0 commit comments