Skip to content

Commit 6a0ef53

Browse files
committed
Added *variance test cases for is_proper_subtype.
1 parent 505c824 commit 6a0ef53

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

mypy/test/testtypes.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
UnboundType, AnyType, Void, CallableType, TupleType, TypeVarDef, Type,
1414
Instance, NoneTyp, ErrorType
1515
)
16-
from mypy.nodes import ARG_POS, ARG_OPT, ARG_STAR
16+
from mypy.nodes import ARG_POS, ARG_OPT, ARG_STAR, CONTRAVARIANT, INVARIANT
1717
from mypy.replacetvars import replace_type_vars
1818
from mypy.subtypes import is_subtype, is_more_precise, is_proper_subtype
1919
from mypy.typefixture import TypeFixture, InterfaceTypeFixture
@@ -213,16 +213,39 @@ def test_is_proper_subtype(self):
213213

214214
assert_true(is_proper_subtype(fx.ga, fx.ga))
215215
assert_true(is_proper_subtype(fx.gdyn, fx.gdyn))
216-
assert_true(is_proper_subtype(fx.gsab, fx.gb))
217-
assert_true(is_proper_subtype(fx.gsab, fx.ga))
218-
assert_true(is_proper_subtype(fx.gb, fx.ga))
219-
assert_false(is_proper_subtype(fx.ga, fx.gb))
220216
assert_false(is_proper_subtype(fx.ga, fx.gdyn))
221217
assert_false(is_proper_subtype(fx.gdyn, fx.ga))
222218

223219
assert_true(is_proper_subtype(fx.t, fx.t))
224220
assert_false(is_proper_subtype(fx.t, fx.s))
225221

222+
def test_is_proper_subtype_covariance(self):
223+
fx = self.fx
224+
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))
230+
231+
def test_is_proper_subtype_contravariance(self):
232+
fx_contra = TypeFixture(CONTRAVARIANT)
233+
234+
assert_true(is_proper_subtype(fx_contra.gsab, fx_contra.gb))
235+
assert_false(is_proper_subtype(fx_contra.gsab, fx_contra.ga))
236+
assert_true(is_proper_subtype(fx_contra.gsaa, fx_contra.gb))
237+
assert_false(is_proper_subtype(fx_contra.gb, fx_contra.ga))
238+
assert_true(is_proper_subtype(fx_contra.ga, fx_contra.gb))
239+
240+
def test_is_proper_subtype_invariance(self):
241+
fx_inv = TypeFixture(INVARIANT)
242+
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))
248+
226249
# Helpers
227250

228251
def tuple(self, *a):

0 commit comments

Comments
 (0)