13
13
UnboundType , AnyType , Void , CallableType , TupleType , TypeVarDef , Type ,
14
14
Instance , NoneTyp , ErrorType
15
15
)
16
- from mypy .nodes import ARG_POS , ARG_OPT , ARG_STAR , CONTRAVARIANT , INVARIANT
16
+ from mypy .nodes import ARG_POS , ARG_OPT , ARG_STAR , CONTRAVARIANT , INVARIANT , COVARIANT
17
17
from mypy .replacetvars import replace_type_vars
18
18
from mypy .subtypes import is_subtype , is_more_precise , is_proper_subtype
19
19
from mypy .typefixture import TypeFixture , InterfaceTypeFixture
@@ -96,7 +96,9 @@ def test_generic_function_type(self):
96
96
97
97
class TypeOpsSuite (Suite ):
98
98
def set_up (self ):
99
- self .fx = TypeFixture ()
99
+ self .fx = TypeFixture (INVARIANT )
100
+ self .fx_co = TypeFixture (COVARIANT )
101
+ self .fx_contra = TypeFixture (CONTRAVARIANT )
100
102
101
103
# expand_type
102
104
@@ -220,16 +222,16 @@ def test_is_proper_subtype(self):
220
222
assert_false (is_proper_subtype (fx .t , fx .s ))
221
223
222
224
def test_is_proper_subtype_covariance (self ):
223
- fx = self .fx
225
+ fx_co = self .fx_co
224
226
225
- assert_true (is_proper_subtype (fx .gsab , fx .gb ))
226
- assert_true (is_proper_subtype (fx .gsab , fx .ga ))
227
- assert_false (is_proper_subtype (fx .gsaa , fx .gb ))
228
- assert_true (is_proper_subtype (fx .gb , fx .ga ))
229
- assert_false (is_proper_subtype (fx .ga , fx .gb ))
227
+ assert_true (is_proper_subtype (fx_co .gsab , fx_co .gb ))
228
+ assert_true (is_proper_subtype (fx_co .gsab , fx_co .ga ))
229
+ assert_false (is_proper_subtype (fx_co .gsaa , fx_co .gb ))
230
+ assert_true (is_proper_subtype (fx_co .gb , fx_co .ga ))
231
+ assert_false (is_proper_subtype (fx_co .ga , fx_co .gb ))
230
232
231
233
def test_is_proper_subtype_contravariance (self ):
232
- fx_contra = TypeFixture ( CONTRAVARIANT )
234
+ fx_contra = self . fx_contra
233
235
234
236
assert_true (is_proper_subtype (fx_contra .gsab , fx_contra .gb ))
235
237
assert_false (is_proper_subtype (fx_contra .gsab , fx_contra .ga ))
@@ -238,13 +240,13 @@ def test_is_proper_subtype_contravariance(self):
238
240
assert_true (is_proper_subtype (fx_contra .ga , fx_contra .gb ))
239
241
240
242
def test_is_proper_subtype_invariance (self ):
241
- fx_inv = TypeFixture ( INVARIANT )
243
+ fx = self . fx
242
244
243
- assert_true (is_proper_subtype (fx_inv .gsab , fx_inv .gb ))
244
- assert_false (is_proper_subtype (fx_inv .gsab , fx_inv .ga ))
245
- assert_false (is_proper_subtype (fx_inv .gsaa , fx_inv .gb ))
246
- assert_false (is_proper_subtype (fx_inv .gb , fx_inv .ga ))
247
- assert_false (is_proper_subtype (fx_inv .ga , fx_inv .gb ))
245
+ assert_true (is_proper_subtype (fx .gsab , fx .gb ))
246
+ assert_false (is_proper_subtype (fx .gsab , fx .ga ))
247
+ assert_false (is_proper_subtype (fx .gsaa , fx .gb ))
248
+ assert_false (is_proper_subtype (fx .gb , fx .ga ))
249
+ assert_false (is_proper_subtype (fx .ga , fx .gb ))
248
250
249
251
# Helpers
250
252
0 commit comments