|
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 |
| 16 | +from mypy.nodes import ARG_POS, ARG_OPT, ARG_STAR, CONTRAVARIANT, INVARIANT |
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
|
@@ -213,16 +213,39 @@ def test_is_proper_subtype(self):
|
213 | 213 |
|
214 | 214 | assert_true(is_proper_subtype(fx.ga, fx.ga))
|
215 | 215 | 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)) |
220 | 216 | assert_false(is_proper_subtype(fx.ga, fx.gdyn))
|
221 | 217 | assert_false(is_proper_subtype(fx.gdyn, fx.ga))
|
222 | 218 |
|
223 | 219 | assert_true(is_proper_subtype(fx.t, fx.t))
|
224 | 220 | assert_false(is_proper_subtype(fx.t, fx.s))
|
225 | 221 |
|
| 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 | + |
226 | 249 | # Helpers
|
227 | 250 |
|
228 | 251 | def tuple(self, *a):
|
|
0 commit comments