@@ -87,7 +87,7 @@ def _find_candidate_type_args(t_param: tp.TypeParameter,
87
87
types ,
88
88
get_subtypes ,
89
89
type_var_map = {},
90
- ignore_use_variance = False ):
90
+ ignore_variance = False ):
91
91
92
92
bound = None
93
93
if t_param .bound :
@@ -107,7 +107,7 @@ def _find_candidate_type_args(t_param: tp.TypeParameter,
107
107
if not base_targ :
108
108
return None
109
109
110
- if t_param .is_invariant ():
110
+ if t_param .is_invariant () or ignore_variance :
111
111
t_args = [base_targ ]
112
112
elif t_param .is_covariant ():
113
113
t_args = _find_types (
@@ -118,7 +118,7 @@ def _find_candidate_type_args(t_param: tp.TypeParameter,
118
118
base_targ , types ,
119
119
not get_subtypes , True , bound , concrete_only = True )
120
120
121
- if not base_targ .is_wildcard () or ignore_use_variance :
121
+ if not base_targ .is_wildcard () or ignore_variance :
122
122
return t_args
123
123
if base_targ .is_covariant ():
124
124
new_types = _find_types (
@@ -138,7 +138,7 @@ def _find_candidate_type_args(t_param: tp.TypeParameter,
138
138
139
139
140
140
def _construct_related_types (etype : tp .ParameterizedType , types , get_subtypes ,
141
- ignore_use_variance = False ):
141
+ ignore_variance = False ):
142
142
type_var_map = OrderedDict ()
143
143
if etype .name == 'Array' :
144
144
types = [t for t in types
@@ -201,7 +201,7 @@ def _construct_related_types(etype: tp.ParameterizedType, types, get_subtypes,
201
201
t_args = _find_candidate_type_args (t_param , etype .type_args [i ],
202
202
types , get_subtypes ,
203
203
type_var_map ,
204
- ignore_use_variance )
204
+ ignore_variance )
205
205
if not t_args :
206
206
# We were not able to construct a subtype of the given
207
207
# parameterized type. Therefore, we give back the given
@@ -221,7 +221,7 @@ def to_type(stype, types):
221
221
222
222
223
223
def _find_types (etype , types , get_subtypes , include_self , bound = None ,
224
- concrete_only = False , ignore_use_variance = False ):
224
+ concrete_only = False , ignore_variance = False ):
225
225
226
226
# Otherwise, if we want to find the supertypes of a given type, `bound`
227
227
# is interpreted a greatest bound.
@@ -242,7 +242,7 @@ def _find_types(etype, types, get_subtypes, include_self, bound=None,
242
242
if isinstance (etype , tp .ParameterizedType ):
243
243
t_set .add (_construct_related_types (
244
244
etype , types , get_subtypes ,
245
- ignore_use_variance = ignore_use_variance ))
245
+ ignore_variance = ignore_variance ))
246
246
if include_self :
247
247
t_set .add (etype )
248
248
else :
@@ -255,10 +255,10 @@ def _find_types(etype, types, get_subtypes, include_self, bound=None,
255
255
256
256
def find_subtypes (etype , types , include_self = False , bound = None ,
257
257
concrete_only = False ,
258
- ignore_use_variance = False ):
258
+ ignore_variance = False ):
259
259
return _find_types (etype , types , get_subtypes = True ,
260
260
include_self = include_self , concrete_only = concrete_only ,
261
- ignore_use_variance = ignore_use_variance )
261
+ ignore_variance = ignore_variance )
262
262
263
263
264
264
def find_supertypes (etype , types , include_self = False , bound = None ,
@@ -594,9 +594,10 @@ def _compute_type_variable_assignments(
594
594
# to prevent creating invalid types, e.g.,
595
595
# * bound: Foo<X, X>
596
596
# * X is assigned to out Number
597
- # * Prevent creating Foo<Long, Number>
597
+ # * class Bar<X, T extends Foo<X, X>>
598
+ # * Prevent creating Bar<out Number, Foo<Long, Number>>
598
599
a_types = find_subtypes (bound , types , True ,
599
- ignore_use_variance = True )
600
+ ignore_variance = True )
600
601
for i , t in enumerate (a_types ):
601
602
if isinstance (t , tp .ParameterizedType ):
602
603
a_types [i ] = t .to_variance_free ()
@@ -657,7 +658,7 @@ def _compute_type_variable_assignments(
657
658
types = [t for t in types if t != c ]
658
659
cls_type , _ = instantiate_type_constructor (
659
660
cls_type , types , True , type_var_map ,
660
- None if variance_choices is None else {}
661
+ None if variance_choices is None else {},
661
662
)
662
663
variance = _get_type_arg_variance (t_param , variance_choices )
663
664
t_arg = cls_type
@@ -736,7 +737,8 @@ def instantiate_parameterized_function(
736
737
types = _get_available_types (None , types , only_regular , primitives = False )
737
738
_ , type_var_map = _compute_type_variable_assignments (
738
739
type_parameters , types , type_var_map = type_var_map ,
739
- variance_choices = None , for_type_constructor = False )
740
+ variance_choices = None , for_type_constructor = False ,
741
+ )
740
742
return type_var_map
741
743
742
744
0 commit comments