@@ -124,18 +124,9 @@ def get_supertypes(self):
124
124
stack .append (supertype )
125
125
return visited
126
126
127
- def substitute_type_args (self , type_map ,
128
- cond = lambda t : t .has_type_variables ()):
129
- t = type_map .get (self )
130
- if t is None or cond (t ):
131
- # Perform type substitution on the bound of the current type variable.
132
- if self .is_type_var () and self .bound is not None :
133
- new_bound = self .bound .substitute_type_args (type_map , cond )
134
- return TypeParameter (self .name , self .variance , new_bound )
135
- # The type parameter does not correspond to an abstract type
136
- # so, there is nothing to substitute.
137
- return self
138
- return t
127
+ def substitute_type (self , type_map ,
128
+ cond = lambda t : t .has_type_variables ()):
129
+ return self
139
130
140
131
def not_related (self , other : Type ):
141
132
return not (self .is_subtype (other ) or other .is_subtype (self ))
@@ -311,6 +302,20 @@ def is_subtype(self, other):
311
302
return False
312
303
return self .bound .is_subtype (other )
313
304
305
+ def substitute_type (self , type_map ,
306
+ cond = lambda t : t .has_type_variables ()):
307
+ t = type_map .get (self )
308
+ if t is None or cond (t ):
309
+ # Perform type substitution on the bound of the current type
310
+ # variable.
311
+ if self .bound is not None :
312
+ new_bound = self .bound .substitute_type (type_map , cond )
313
+ return TypeParameter (self .name , self .variance , new_bound )
314
+ # The type parameter does not correspond to an abstract type
315
+ # so, there is nothing to substitute.
316
+ return self
317
+ return t
318
+
314
319
def __eq__ (self , other ):
315
320
return (self .__class__ == other .__class__ and
316
321
self .name == other .name and
@@ -359,10 +364,10 @@ def get_type_variables(self, factory):
359
364
else :
360
365
return {}
361
366
362
- def substitute_type_args (self , type_map ,
363
- cond = lambda t : t .has_type_variables ()):
367
+ def substitute_type (self , type_map ,
368
+ cond = lambda t : t .has_type_variables ()):
364
369
if self .bound is not None :
365
- new_bound = self .bound .substitute_type_args (type_map , cond )
370
+ new_bound = self .bound .substitute_type (type_map , cond )
366
371
return WildCardType (new_bound , variance = self .variance )
367
372
t = type_map .get (self )
368
373
if t is None or cond (t ):
@@ -414,7 +419,7 @@ def is_primitive(self):
414
419
415
420
416
421
def substitute_type (t , type_map ):
417
- return t .substitute_type_args (type_map , lambda t : False )
422
+ return t .substitute_type (type_map , lambda t : False )
418
423
419
424
420
425
def perform_type_substitution (etype , type_map ,
@@ -437,7 +442,7 @@ class X<T> : Y<Z<T>>()
437
442
supertypes = []
438
443
for t in etype .supertypes :
439
444
if t .is_parameterized ():
440
- supertypes .append (t .substitute_type_args (type_map ))
445
+ supertypes .append (t .substitute_type (type_map ))
441
446
else :
442
447
supertypes .append (t )
443
448
type_params = []
@@ -678,10 +683,10 @@ def get_type_variables(self, factory) -> Dict[TypeParameter, Set[Type]]:
678
683
continue
679
684
return type_vars
680
685
681
- def substitute_type_args (self , type_map , cond = lambda t : t .has_type_variables ()):
686
+ def substitute_type (self , type_map , cond = lambda t : t .has_type_variables ()):
682
687
type_args = []
683
688
for t_arg in self .type_args :
684
- type_args .append (t_arg .substitute_type_args (type_map , cond ))
689
+ type_args .append (t_arg .substitute_type (type_map , cond ))
685
690
new_type_map = {
686
691
tp : type_args [i ]
687
692
for i , tp in enumerate (self .t_constructor .type_parameters )
0 commit comments