]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.10] bpo-46676: Make ParamSpec args and kwargs equal to themselves (GH-31203) ...
authorGregory Beauregard <greg@greg.red>
Tue, 8 Feb 2022 08:41:13 +0000 (00:41 -0800)
committerGitHub <noreply@github.com>
Tue, 8 Feb 2022 08:41:13 +0000 (10:41 +0200)
(cherry picked from commit c8b62bbe46e20d4b6dd556f2fa85960d1269aa45)

Co-authored-by: Gregory Beauregard <greg@greg.red>
Lib/test/test_typing.py
Lib/typing.py
Misc/NEWS.d/next/Library/2022-02-07-19-20-42.bpo-46676.3Aws1o.rst [new file with mode: 0644]

index 341be1dd031ab17429775025cb747bdad3cc5a7f..62762418b3f4a8a3f8fc3a6397182514a002aad8 100644 (file)
@@ -4823,12 +4823,20 @@ class ParamSpecTests(BaseTestCase):
 
     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")
 
index 7743c7f76bde8fb6769bd8ce0a36910d668245f8..135ca582177b9f4928a5004ea1f26ec9ad66ad20 100644 (file)
@@ -830,6 +830,11 @@ class ParamSpecArgs(_Final, _Immutable, _root=True):
     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.
@@ -849,6 +854,11 @@ class ParamSpecKwargs(_Final, _Immutable, _root=True):
     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 (file)
index 0000000..408412e
--- /dev/null
@@ -0,0 +1 @@
+Make :data:`typing.ParamSpec` args and kwargs equal to themselves. Patch by Gregory Beauregard.