Skip to content

Commit 6905d43

Browse files
authored
typing ParamSpec (#5837)
* Add cspell * TypeVar * ParamSpec * refactor * TypeVarTuple repr * Remove expectedFailure
1 parent 1ae0781 commit 6905d43

File tree

5 files changed

+404
-61
lines changed

5 files changed

+404
-61
lines changed

.cspell.dict/python-more.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ basicsize
1717
bdfl
1818
bigcharset
1919
bignum
20+
bivariant
2021
breakpointhook
2122
cformat
2223
chunksize

Lib/test/test_types.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -742,8 +742,6 @@ def test_instancecheck_and_subclasscheck(self):
742742
self.assertTrue(issubclass(dict, x))
743743
self.assertFalse(issubclass(list, x))
744744

745-
# TODO: RUSTPYTHON
746-
@unittest.expectedFailure
747745
def test_instancecheck_and_subclasscheck_order(self):
748746
T = typing.TypeVar('T')
749747

@@ -790,17 +788,13 @@ def __subclasscheck__(cls, sub):
790788
self.assertTrue(issubclass(int, x))
791789
self.assertRaises(ZeroDivisionError, issubclass, list, x)
792790

793-
# TODO: RUSTPYTHON
794-
@unittest.expectedFailure
795791
def test_or_type_operator_with_TypeVar(self):
796792
TV = typing.TypeVar('T')
797793
assert TV | str == typing.Union[TV, str]
798794
assert str | TV == typing.Union[str, TV]
799795
self.assertIs((int | TV)[int], int)
800796
self.assertIs((TV | int)[int], int)
801797

802-
# TODO: RUSTPYTHON
803-
@unittest.expectedFailure
804798
def test_union_args(self):
805799
def check(arg, expected):
806800
clear_typing_caches()
@@ -893,16 +887,12 @@ def test_union_copy(self):
893887
self.assertEqual(copied.__args__, orig.__args__)
894888
self.assertEqual(copied.__parameters__, orig.__parameters__)
895889

896-
# TODO: RUSTPYTHON
897-
@unittest.expectedFailure
898890
def test_union_parameter_substitution_errors(self):
899891
T = typing.TypeVar("T")
900892
x = int | T
901893
with self.assertRaises(TypeError):
902894
x[int, str]
903895

904-
# TODO: RUSTPYTHON
905-
@unittest.expectedFailure
906896
def test_or_type_operator_with_forward(self):
907897
T = typing.TypeVar('T')
908898
ForwardAfter = T | 'Forward'

Lib/test/test_typing.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -464,8 +464,6 @@ def test_union_unique(self):
464464
self.assertEqual(Union[X, int].__parameters__, (X,))
465465
self.assertIs(Union[X, int].__origin__, Union)
466466

467-
# TODO: RUSTPYTHON
468-
@unittest.expectedFailure
469467
def test_or(self):
470468
X = TypeVar('X')
471469
# use a string because str doesn't implement
@@ -657,7 +655,6 @@ class X[T]: ...
657655
self.assertFalse(T.has_default())
658656

659657
# TODO: RUSTPYTHON
660-
@unittest.expectedFailure
661658
def test_paramspec(self):
662659
P = ParamSpec('P', default=(str, int))
663660
self.assertEqual(P.__default__, (str, int))
@@ -686,7 +683,6 @@ class X[**P]: ...
686683
self.assertFalse(P.has_default())
687684

688685
# TODO: RUSTPYTHON
689-
@unittest.expectedFailure
690686
def test_typevartuple(self):
691687
Ts = TypeVarTuple('Ts', default=Unpack[Tuple[str, int]])
692688
self.assertEqual(Ts.__default__, Unpack[Tuple[str, int]])
@@ -1289,15 +1285,13 @@ class Gen[*Ts]: ...
12891285
class TypeVarTupleTests(BaseTestCase):
12901286

12911287
# TODO: RUSTPYTHON
1292-
@unittest.expectedFailure
12931288
def test_name(self):
12941289
Ts = TypeVarTuple('Ts')
12951290
self.assertEqual(Ts.__name__, 'Ts')
12961291
Ts2 = TypeVarTuple('Ts2')
12971292
self.assertEqual(Ts2.__name__, 'Ts2')
12981293

12991294
# TODO: RUSTPYTHON
1300-
@unittest.expectedFailure
13011295
def test_module(self):
13021296
Ts = TypeVarTuple('Ts')
13031297
self.assertEqual(Ts.__module__, __name__)
@@ -2050,7 +2044,6 @@ class TypeVarTuplePicklingTests(BaseTestCase):
20502044
# statements at the start of each test.
20512045

20522046
# TODO: RUSTPYTHON
2053-
@unittest.expectedFailure
20542047
@all_pickle_protocols
20552048
def test_pickling_then_unpickling_results_in_same_identity(self, proto):
20562049
global global_Ts1 # See explanation at start of class.
@@ -4278,7 +4271,6 @@ class Node(Generic[T]): ...
42784271
self.assertEqual(t, deepcopy(t))
42794272

42804273
# TODO: RUSTPYTHON
4281-
@unittest.expectedFailure
42824274
def test_immutability_by_copy_and_pickle(self):
42834275
# Special forms like Union, Any, etc., generic aliases to containers like List,
42844276
# Mapping, etc., and type variabcles are considered immutable by copy and pickle.
@@ -8801,7 +8793,6 @@ def test_cannot_subscript(self):
88018793
class ParamSpecTests(BaseTestCase):
88028794

88038795
# TODO: RUSTPYTHON
8804-
@unittest.expectedFailure
88058796
def test_basic_plain(self):
88068797
P = ParamSpec('P')
88078798
self.assertEqual(P, P)
@@ -9010,7 +9001,6 @@ class Y(Generic[P, T]):
90109001
self.assertEqual(B.__args__, ((int, str,), Tuple[bytes, float]))
90119002

90129003
# TODO: RUSTPYTHON
9013-
@unittest.expectedFailure
90149004
def test_var_substitution(self):
90159005
P = ParamSpec("P")
90169006
subst = P.__typing_subst__
@@ -9022,7 +9012,6 @@ def test_var_substitution(self):
90229012
self.assertEqual(subst(Concatenate[int, P]), Concatenate[int, P])
90239013

90249014
# TODO: RUSTPYTHON
9025-
@unittest.expectedFailure
90269015
def test_bad_var_substitution(self):
90279016
T = TypeVar('T')
90289017
P = ParamSpec('P')
@@ -9241,7 +9230,6 @@ def test_dir(self):
92419230
self.assertIn(required_item, dir_items)
92429231

92439232
# TODO: RUSTPYTHON
9244-
@unittest.expectedFailure
92459233
def test_valid_uses(self):
92469234
P = ParamSpec('P')
92479235
T = TypeVar('T')
@@ -9719,8 +9707,6 @@ def test_constructor(self):
97199707
with self.assertRaises(TypeError):
97209708
type(NoDefault)(1)
97219709

9722-
# TODO: RUSTPYTHON
9723-
@unittest.expectedFailure
97249710
def test_repr(self):
97259711
self.assertEqual(repr(NoDefault), 'typing.NoDefault')
97269712

vm/src/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ impl ExecutingFrame<'_> {
12821282
bytecode::Instruction::TypeVarTuple => {
12831283
let type_var_tuple_name = self.pop_value();
12841284
let type_var_tuple: PyObjectRef =
1285-
_typing::make_typevartuple(type_var_tuple_name.clone())
1285+
_typing::make_typevartuple(type_var_tuple_name.clone(), vm)
12861286
.into_ref(&vm.ctx)
12871287
.into();
12881288
self.push_value(type_var_tuple);

0 commit comments

Comments
 (0)