Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Lib/test/test_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4924,12 +4924,20 @@ def test_valid_uses(self):

def test_args_kwargs(self):
P = ParamSpec('P')
P_2 = ParamSpec('P_2')
self.assertIn('args', dir(P))
self.assertIn('kwargs', dir(P))
self.assertIsInstance(P.args, ParamSpecArgs)
self.assertIsInstance(P.kwargs, ParamSpecKwargs)
self.assertIs(P.args.__origin__, P)
self.assertIs(P.kwargs.__origin__, P)
self.assertEqual(P.args, P.args)
Comment thread
GBeauregard marked this conversation as resolved.
self.assertEqual(P.kwargs, P.kwargs)
self.assertNotEqual(P.args, P_2.args)
self.assertNotEqual(P.kwargs, P_2.kwargs)
Comment thread
GBeauregard marked this conversation as resolved.
self.assertNotEqual(P.args, P.kwargs)
self.assertNotEqual(P.kwargs, P.args)
self.assertNotEqual(P.args, P_2.kwargs)
self.assertEqual(repr(P.args), "P.args")
self.assertEqual(repr(P.kwargs), "P.kwargs")

Expand Down
10 changes: 10 additions & 0 deletions Lib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -837,6 +837,11 @@ def __init__(self, origin):
def __repr__(self):
return f"{self.__origin__.__name__}.args"

def __eq__(self, other):
if not isinstance(other, ParamSpecArgs):
return NotImplemented
return self.__origin__ == other.__origin__


class ParamSpecKwargs(_Final, _Immutable, _root=True):
"""The kwargs for a ParamSpec object.
Expand All @@ -856,6 +861,11 @@ def __init__(self, origin):
def __repr__(self):
return f"{self.__origin__.__name__}.kwargs"

def __eq__(self, other):
if not isinstance(other, ParamSpecKwargs):
return NotImplemented
return self.__origin__ == other.__origin__


class ParamSpec(_Final, _Immutable, _TypeVarLike, _root=True):
"""Parameter specification variable.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Make :data:`typing.ParamSpec` args and kwargs equal to themselves. Patch by Gregory Beauregard.