Skip to content

Commit c8b62bb

Browse files
authored
bpo-46676: Make ParamSpec args and kwargs equal to themselves (GH-31203)
1 parent e959dd9 commit c8b62bb

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

Lib/test/test_typing.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4965,12 +4965,20 @@ def test_valid_uses(self):
49654965

49664966
def test_args_kwargs(self):
49674967
P = ParamSpec('P')
4968+
P_2 = ParamSpec('P_2')
49684969
self.assertIn('args', dir(P))
49694970
self.assertIn('kwargs', dir(P))
49704971
self.assertIsInstance(P.args, ParamSpecArgs)
49714972
self.assertIsInstance(P.kwargs, ParamSpecKwargs)
49724973
self.assertIs(P.args.__origin__, P)
49734974
self.assertIs(P.kwargs.__origin__, P)
4975+
self.assertEqual(P.args, P.args)
4976+
self.assertEqual(P.kwargs, P.kwargs)
4977+
self.assertNotEqual(P.args, P_2.args)
4978+
self.assertNotEqual(P.kwargs, P_2.kwargs)
4979+
self.assertNotEqual(P.args, P.kwargs)
4980+
self.assertNotEqual(P.kwargs, P.args)
4981+
self.assertNotEqual(P.args, P_2.kwargs)
49744982
self.assertEqual(repr(P.args), "P.args")
49754983
self.assertEqual(repr(P.kwargs), "P.kwargs")
49764984

Lib/typing.py

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

862+
def __eq__(self, other):
863+
if not isinstance(other, ParamSpecArgs):
864+
return NotImplemented
865+
return self.__origin__ == other.__origin__
866+
862867

863868
class ParamSpecKwargs(_Final, _Immutable, _root=True):
864869
"""The kwargs for a ParamSpec object.
@@ -878,6 +883,11 @@ def __init__(self, origin):
878883
def __repr__(self):
879884
return f"{self.__origin__.__name__}.kwargs"
880885

886+
def __eq__(self, other):
887+
if not isinstance(other, ParamSpecKwargs):
888+
return NotImplemented
889+
return self.__origin__ == other.__origin__
890+
881891

882892
class ParamSpec(_Final, _Immutable, _TypeVarLike, _root=True):
883893
"""Parameter specification variable.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Make :data:`typing.ParamSpec` args and kwargs equal to themselves. Patch by Gregory Beauregard.

0 commit comments

Comments
 (0)