Skip to content

Commit cbdcae5

Browse files
authored
[3.10] bpo-46676: Make ParamSpec args and kwargs equal to themselves (GH-31203) (GH-31210)
(cherry picked from commit c8b62bb) Co-authored-by: Gregory Beauregard <greg@greg.red>
1 parent 9539400 commit cbdcae5

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
@@ -4823,12 +4823,20 @@ def test_valid_uses(self):
48234823

48244824
def test_args_kwargs(self):
48254825
P = ParamSpec('P')
4826+
P_2 = ParamSpec('P_2')
48264827
self.assertIn('args', dir(P))
48274828
self.assertIn('kwargs', dir(P))
48284829
self.assertIsInstance(P.args, ParamSpecArgs)
48294830
self.assertIsInstance(P.kwargs, ParamSpecKwargs)
48304831
self.assertIs(P.args.__origin__, P)
48314832
self.assertIs(P.kwargs.__origin__, P)
4833+
self.assertEqual(P.args, P.args)
4834+
self.assertEqual(P.kwargs, P.kwargs)
4835+
self.assertNotEqual(P.args, P_2.args)
4836+
self.assertNotEqual(P.kwargs, P_2.kwargs)
4837+
self.assertNotEqual(P.args, P.kwargs)
4838+
self.assertNotEqual(P.kwargs, P.args)
4839+
self.assertNotEqual(P.args, P_2.kwargs)
48324840
self.assertEqual(repr(P.args), "P.args")
48334841
self.assertEqual(repr(P.kwargs), "P.kwargs")
48344842

Lib/typing.py

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

833+
def __eq__(self, other):
834+
if not isinstance(other, ParamSpecArgs):
835+
return NotImplemented
836+
return self.__origin__ == other.__origin__
837+
833838

834839
class ParamSpecKwargs(_Final, _Immutable, _root=True):
835840
"""The kwargs for a ParamSpec object.
@@ -849,6 +854,11 @@ def __init__(self, origin):
849854
def __repr__(self):
850855
return f"{self.__origin__.__name__}.kwargs"
851856

857+
def __eq__(self, other):
858+
if not isinstance(other, ParamSpecKwargs):
859+
return NotImplemented
860+
return self.__origin__ == other.__origin__
861+
852862

853863
class ParamSpec(_Final, _Immutable, _TypeVarLike, _root=True):
854864
"""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)