[Python-checkins] bpo-46676: Make ParamSpec args and kwargs equal to themselves (GH-31203)

serhiy-storchaka webhook-mailer at python.org
Tue Feb 8 02:47:06 EST 2022


https://github.com/python/cpython/commit/c8b62bbe46e20d4b6dd556f2fa85960d1269aa45
commit: c8b62bbe46e20d4b6dd556f2fa85960d1269aa45
branch: main
author: Gregory Beauregard <greg at greg.red>
committer: serhiy-storchaka <storchaka at gmail.com>
date: 2022-02-08T09:46:58+02:00
summary:

bpo-46676: Make ParamSpec args and kwargs equal to themselves (GH-31203)

files:
A Misc/NEWS.d/next/Library/2022-02-07-19-20-42.bpo-46676.3Aws1o.rst
M Lib/test/test_typing.py
M Lib/typing.py

diff --git a/Lib/test/test_typing.py b/Lib/test/test_typing.py
index a37bb43296929..4d1c50ce73549 100644
--- a/Lib/test/test_typing.py
+++ b/Lib/test/test_typing.py
@@ -4965,12 +4965,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)
+        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.kwargs), "P.kwargs")
 
diff --git a/Lib/typing.py b/Lib/typing.py
index d1d513062394c..0ee5c8596a021 100644
--- a/Lib/typing.py
+++ b/Lib/typing.py
@@ -859,6 +859,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.
@@ -878,6 +883,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.
diff --git a/Misc/NEWS.d/next/Library/2022-02-07-19-20-42.bpo-46676.3Aws1o.rst b/Misc/NEWS.d/next/Library/2022-02-07-19-20-42.bpo-46676.3Aws1o.rst
new file mode 100644
index 0000000000000..408412e6ff15d
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-02-07-19-20-42.bpo-46676.3Aws1o.rst
@@ -0,0 +1 @@
+Make :data:`typing.ParamSpec` args and kwargs equal to themselves. Patch by Gregory Beauregard.



More information about the Python-checkins mailing list