mirror of
https://github.com/python/cpython.git
synced 2025-08-01 07:33:08 +00:00
[3.10] bpo-46676: Make ParamSpec args and kwargs equal to themselves (GH-31203) (GH-31210)
(cherry picked from commit c8b62bbe46
)
Co-authored-by: Gregory Beauregard <greg@greg.red>
This commit is contained in:
parent
9539400390
commit
cbdcae5ab9
3 changed files with 19 additions and 0 deletions
|
@ -4823,12 +4823,20 @@ class ParamSpecTests(BaseTestCase):
|
||||||
|
|
||||||
def test_args_kwargs(self):
|
def test_args_kwargs(self):
|
||||||
P = ParamSpec('P')
|
P = ParamSpec('P')
|
||||||
|
P_2 = ParamSpec('P_2')
|
||||||
self.assertIn('args', dir(P))
|
self.assertIn('args', dir(P))
|
||||||
self.assertIn('kwargs', dir(P))
|
self.assertIn('kwargs', dir(P))
|
||||||
self.assertIsInstance(P.args, ParamSpecArgs)
|
self.assertIsInstance(P.args, ParamSpecArgs)
|
||||||
self.assertIsInstance(P.kwargs, ParamSpecKwargs)
|
self.assertIsInstance(P.kwargs, ParamSpecKwargs)
|
||||||
self.assertIs(P.args.__origin__, P)
|
self.assertIs(P.args.__origin__, P)
|
||||||
self.assertIs(P.kwargs.__origin__, P)
|
self.assertIs(P.kwargs.__origin__, P)
|
||||||
|
self.assertEqual(P.args, P.args)
|
||||||
|
self.assertEqual(P.kwargs, P.kwargs)
|
||||||
|
self.assertNotEqual(P.args, P_2.args)
|
||||||
|
self.assertNotEqual(P.kwargs, P_2.kwargs)
|
||||||
|
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.args), "P.args")
|
||||||
self.assertEqual(repr(P.kwargs), "P.kwargs")
|
self.assertEqual(repr(P.kwargs), "P.kwargs")
|
||||||
|
|
||||||
|
|
|
@ -830,6 +830,11 @@ class ParamSpecArgs(_Final, _Immutable, _root=True):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.__origin__.__name__}.args"
|
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):
|
class ParamSpecKwargs(_Final, _Immutable, _root=True):
|
||||||
"""The kwargs for a ParamSpec object.
|
"""The kwargs for a ParamSpec object.
|
||||||
|
@ -849,6 +854,11 @@ class ParamSpecKwargs(_Final, _Immutable, _root=True):
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return f"{self.__origin__.__name__}.kwargs"
|
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):
|
class ParamSpec(_Final, _Immutable, _TypeVarLike, _root=True):
|
||||||
"""Parameter specification variable.
|
"""Parameter specification variable.
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Make :data:`typing.ParamSpec` args and kwargs equal to themselves. Patch by Gregory Beauregard.
|
Loading…
Add table
Add a link
Reference in a new issue