Skip to content

Commit 29e452a

Browse files
committed
typing.TypeVar
1 parent d16d376 commit 29e452a

File tree

3 files changed

+286
-69
lines changed

3 files changed

+286
-69
lines changed

Lib/test/test_typing.py

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,6 @@ def test_alias(self):
374374

375375
class TypeVarTests(BaseTestCase):
376376
# TODO: RUSTPYTHON
377-
@unittest.expectedFailure
378377
def test_basic_plain(self):
379378
T = TypeVar('T')
380379
# T equals itself.
@@ -405,7 +404,6 @@ def test_basic_with_exec(self):
405404
self.assertIs(T.__module__, None)
406405

407406
# TODO: RUSTPYTHON
408-
@unittest.expectedFailure
409407
def test_attributes(self):
410408
T_bound = TypeVar('T_bound', bound=int)
411409
self.assertEqual(T_bound.__name__, 'T_bound')
@@ -448,14 +446,11 @@ def test_typevar_subclass_type_error(self):
448446
issubclass(T, int)
449447

450448
# TODO: RUSTPYTHON
451-
@unittest.expectedFailure
452449
def test_constrained_error(self):
453450
with self.assertRaises(TypeError):
454451
X = TypeVar('X', int)
455452
X
456453

457-
# TODO: RUSTPYTHON
458-
@unittest.expectedFailure
459454
def test_union_unique(self):
460455
X = TypeVar('X')
461456
Y = TypeVar('Y')
@@ -486,7 +481,6 @@ def test_union_constrained(self):
486481
self.assertNotEqual(Union[A, str], Union[A])
487482

488483
# TODO: RUSTPYTHON
489-
@unittest.expectedFailure
490484
def test_repr(self):
491485
self.assertEqual(repr(T), '~T')
492486
self.assertEqual(repr(KT), '~KT')
@@ -502,7 +496,6 @@ def test_no_redefinition(self):
502496
self.assertNotEqual(TypeVar('T', int, str), TypeVar('T', int, str))
503497

504498
# TODO: RUSTPYTHON
505-
@unittest.expectedFailure
506499
def test_cannot_subclass(self):
507500
with self.assertRaisesRegex(TypeError, NOT_A_BASE_TYPE % 'TypeVar'):
508501
class V(TypeVar): pass
@@ -515,8 +508,6 @@ def test_cannot_instantiate_vars(self):
515508
with self.assertRaises(TypeError):
516509
TypeVar('A')()
517510

518-
# TODO: RUSTPYTHON
519-
@unittest.expectedFailure
520511
def test_bound_errors(self):
521512
with self.assertRaises(TypeError):
522513
TypeVar('X', bound=Union)
@@ -533,22 +524,16 @@ def test_missing__name__(self):
533524
)
534525
exec(code, {})
535526

536-
# TODO: RUSTPYTHON
537-
@unittest.expectedFailure
538527
def test_no_bivariant(self):
539528
with self.assertRaises(ValueError):
540529
TypeVar('T', covariant=True, contravariant=True)
541530

542-
# TODO: RUSTPYTHON
543-
@unittest.expectedFailure
544531
def test_cannot_combine_explicit_and_infer(self):
545532
with self.assertRaises(ValueError):
546533
TypeVar('T', covariant=True, infer_variance=True)
547534
with self.assertRaises(ValueError):
548535
TypeVar('T', contravariant=True, infer_variance=True)
549536

550-
# TODO: RUSTPYTHON
551-
@unittest.expectedFailure
552537
def test_var_substitution(self):
553538
T = TypeVar('T')
554539
subst = T.__typing_subst__
@@ -591,7 +576,6 @@ def test_many_weakrefs(self):
591576
del vals
592577

593578
# TODO: RUSTPYTHON
594-
@unittest.expectedFailure
595579
def test_constructor(self):
596580
T = TypeVar(name="T")
597581
self.assertEqual(T.__name__, "T")
@@ -648,8 +632,6 @@ def test_constructor(self):
648632
self.assertIs(T.__infer_variance__, True)
649633

650634
class TypeParameterDefaultsTests(BaseTestCase):
651-
# TODO: RUSTPYTHON
652-
@unittest.expectedFailure
653635
def test_typevar(self):
654636
T = TypeVar('T', default=int)
655637
self.assertEqual(T.__default__, int)
@@ -844,8 +826,6 @@ class A(Generic[T, U, DefaultStrT]): ...
844826
):
845827
Test = A[int]
846828

847-
# TODO: RUSTPYTHON
848-
@unittest.expectedFailure
849829
def test_pickle(self):
850830
global U, U_co, U_contra, U_default # pickle wants to reference the class by name
851831
U = TypeVar('U')
@@ -3695,8 +3675,6 @@ def test_repr(self):
36953675
self.assertEqual(repr(MySimpleMapping),
36963676
f"<class '{__name__}.MySimpleMapping'>")
36973677

3698-
# TODO: RUSTPYTHON
3699-
@unittest.expectedFailure
37003678
def test_chain_repr(self):
37013679
T = TypeVar('T')
37023680
S = TypeVar('S')
@@ -3721,8 +3699,6 @@ class C(Generic[T]):
37213699
self.assertTrue(str(Z).endswith(
37223700
'.C[typing.Tuple[str, int]]'))
37233701

3724-
# TODO: RUSTPYTHON
3725-
@unittest.expectedFailure
37263702
def test_new_repr(self):
37273703
T = TypeVar('T')
37283704
U = TypeVar('U', covariant=True)
@@ -3734,8 +3710,6 @@ def test_new_repr(self):
37343710
self.assertEqual(repr(List[S][T][int]), 'typing.List[int]')
37353711
self.assertEqual(repr(List[int]), 'typing.List[int]')
37363712

3737-
# TODO: RUSTPYTHON
3738-
@unittest.expectedFailure
37393713
def test_new_repr_complex(self):
37403714
T = TypeVar('T')
37413715
TS = TypeVar('TS')
@@ -3862,8 +3836,6 @@ def test_orig_bases(self):
38623836
class C(typing.Dict[str, T]): ...
38633837
self.assertEqual(C.__orig_bases__, (typing.Dict[str, T],))
38643838

3865-
# TODO: RUSTPYTHON
3866-
@unittest.expectedFailure
38673839
def test_naive_runtime_checks(self):
38683840
def naive_dict_check(obj, tp):
38693841
# Check if a dictionary conforms to Dict type
@@ -3919,8 +3891,6 @@ class D(C, List[T][U][V]): ...
39193891
self.assertEqual(C.__orig_bases__, (List[T][U][V],))
39203892
self.assertEqual(D.__orig_bases__, (C, List[T][U][V]))
39213893

3922-
# TODO: RUSTPYTHON
3923-
@unittest.expectedFailure
39243894
def test_subscript_meta(self):
39253895
T = TypeVar('T')
39263896
class Meta(type): ...
@@ -3972,8 +3942,6 @@ class A(Generic[T]):
39723942
self.assertTrue(repr(Tuple[mod_generics_cache.B.A[str]])
39733943
.endswith('mod_generics_cache.B.A[str]]'))
39743944

3975-
# TODO: RUSTPYTHON
3976-
@unittest.expectedFailure
39773945
def test_extended_generic_rules_eq(self):
39783946
T = TypeVar('T')
39793947
U = TypeVar('U')
@@ -3990,8 +3958,6 @@ class Derived(Base): ...
39903958
self.assertEqual(Callable[[T], T][KT], Callable[[KT], KT])
39913959
self.assertEqual(Callable[..., List[T]][int], Callable[..., List[int]])
39923960

3993-
# TODO: RUSTPYTHON
3994-
@unittest.expectedFailure
39953961
def test_extended_generic_rules_repr(self):
39963962
T = TypeVar('T')
39973963
self.assertEqual(repr(Union[Tuple, Callable]).replace('typing.', ''),
@@ -4298,8 +4264,6 @@ class C(B[int]):
42984264
)
42994265
del PP
43004266

4301-
# TODO: RUSTPYTHON
4302-
@unittest.expectedFailure
43034267
def test_copy_and_deepcopy(self):
43044268
T = TypeVar('T')
43054269
class Node(Generic[T]): ...
@@ -8419,8 +8383,6 @@ def test_order_in_union(self):
84198383
with self.subTest(args=args):
84208384
self.assertEqual(expr2, Union[args])
84218385

8422-
# TODO: RUSTPYTHON
8423-
@unittest.expectedFailure
84248386
def test_specialize(self):
84258387
L = Annotated[List[T], "my decoration"]
84268388
LI = Annotated[List[int], "my decoration"]
@@ -8471,8 +8433,6 @@ def __eq__(self, other):
84718433
self.assertEqual(a.x, c.x)
84728434
self.assertEqual(a.classvar, c.classvar)
84738435

8474-
# TODO: RUSTPYTHON
8475-
@unittest.expectedFailure
84768436
def test_instantiate_generic(self):
84778437
MyCount = Annotated[typing.Counter[T], "my decoration"]
84788438
self.assertEqual(MyCount([4, 4, 5]), {4: 2, 5: 1})
@@ -8601,8 +8561,6 @@ class _Annotated_test_G(Generic[T]):
86018561
self.assertEqual(x.bar, 'abc')
86028562
self.assertEqual(x.x, 1)
86038563

8604-
# TODO: RUSTPYTHON
8605-
@unittest.expectedFailure
86068564
def test_subst(self):
86078565
dec = "a decoration"
86088566
dec2 = "another decoration"
@@ -8748,8 +8706,6 @@ def test_typevar_subst(self):
87488706
with self.assertRaises(TypeError):
87498707
J[int]
87508708

8751-
# TODO: RUSTPYTHON
8752-
@unittest.expectedFailure
87538709
def test_annotated_in_other_types(self):
87548710
X = List[Annotated[T, 5]]
87558711
self.assertEqual(X[int], List[Annotated[int, 5]])

vm/src/builtins/type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,7 @@ fn best_base<'a>(bases: &'a [PyTypeRef], vm: &VirtualMachine) -> PyResult<&'a Py
14981498
if !base_i.slots.flags.has_feature(PyTypeFlags::BASETYPE) {
14991499
return Err(vm.new_type_error(format!(
15001500
"type '{}' is not an acceptable base type",
1501-
base_i.name()
1501+
base_i.slot_name()
15021502
)));
15031503
}
15041504

0 commit comments

Comments
 (0)