Skip to content

Commit 5be289a

Browse files
authored
ParamSpec: backport bpo-46676 (#1059)
1 parent dcedbb1 commit 5be289a

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

CHANGELOG

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Release 4.x.x
22

3+
- `ParamSpec` args and kwargs are now equal to themselves. Backport from
4+
bpo-46676. Patch by Gregory Beauregard (@GBeauregard).
35
- Add `reveal_type`. Backport from bpo-46414.
46
- Runtime support for PEP 681 and `typing_extensions.dataclass_transform`.
57
- `Annotated` can now wrap `ClassVar` and `Final`. Backport from

src/test_typing_extensions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2057,15 +2057,24 @@ def test_valid_uses(self):
20572057
self.assertTrue(hasattr(P, 'args'))
20582058
self.assertTrue(hasattr(P, 'kwargs'))
20592059

2060+
@skipIf((3, 10, 0) <= sys.version_info[:3] <= (3, 10, 2), "Needs bpo-46676.")
20602061
def test_args_kwargs(self):
20612062
P = ParamSpec('P')
2063+
P_2 = ParamSpec('P_2')
20622064
# Note: not in dir(P) because of __class__ hacks
20632065
self.assertTrue(hasattr(P, 'args'))
20642066
self.assertTrue(hasattr(P, 'kwargs'))
20652067
self.assertIsInstance(P.args, ParamSpecArgs)
20662068
self.assertIsInstance(P.kwargs, ParamSpecKwargs)
20672069
self.assertIs(P.args.__origin__, P)
20682070
self.assertIs(P.kwargs.__origin__, P)
2071+
self.assertEqual(P.args, P.args)
2072+
self.assertEqual(P.kwargs, P.kwargs)
2073+
self.assertNotEqual(P.args, P_2.args)
2074+
self.assertNotEqual(P.kwargs, P_2.kwargs)
2075+
self.assertNotEqual(P.args, P.kwargs)
2076+
self.assertNotEqual(P.kwargs, P.args)
2077+
self.assertNotEqual(P.args, P_2.kwargs)
20692078
self.assertEqual(repr(P.args), "P.args")
20702079
self.assertEqual(repr(P.kwargs), "P.kwargs")
20712080

src/typing_extensions.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1635,6 +1635,11 @@ def __init__(self, origin):
16351635
def __repr__(self):
16361636
return f"{self.__origin__.__name__}.args"
16371637

1638+
def __eq__(self, other):
1639+
if not isinstance(other, ParamSpecArgs):
1640+
return NotImplemented
1641+
return self.__origin__ == other.__origin__
1642+
16381643
class ParamSpecKwargs(_Immutable):
16391644
"""The kwargs for a ParamSpec object.
16401645
@@ -1653,6 +1658,11 @@ def __init__(self, origin):
16531658
def __repr__(self):
16541659
return f"{self.__origin__.__name__}.kwargs"
16551660

1661+
def __eq__(self, other):
1662+
if not isinstance(other, ParamSpecKwargs):
1663+
return NotImplemented
1664+
return self.__origin__ == other.__origin__
1665+
16561666
# 3.10+
16571667
if hasattr(typing, 'ParamSpec'):
16581668
ParamSpec = typing.ParamSpec

0 commit comments

Comments
 (0)