summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorCF Bolz-Tereick <cfbolz@gmx.de>2024-12-27 01:03:47 (GMT)
committerGitHub <noreply@github.com>2024-12-27 01:03:47 (GMT)
commit401bba6b58497ce59e7b45ad33e43ae8c67abcb9 (patch)
tree2674719f2259b7ad3d15d3921eee06df22310618 /Lib
parentea2b53739f1128184b4140decbeffeac6cfe966f (diff)
downloadcpython-401bba6b58497ce59e7b45ad33e43ae8c67abcb9.zip
cpython-401bba6b58497ce59e7b45ad33e43ae8c67abcb9.tar.gz
cpython-401bba6b58497ce59e7b45ad33e43ae8c67abcb9.tar.bz2
gh-127537: Add __class_getitem__ to the python implementation of functools.partial (#127537)
Diffstat (limited to 'Lib')
-rw-r--r--Lib/functools.py3
-rw-r--r--Lib/test/test_functools.py6
2 files changed, 9 insertions, 0 deletions
diff --git a/Lib/functools.py b/Lib/functools.py
index eff6540..786b8ae 100644
--- a/Lib/functools.py
+++ b/Lib/functools.py
@@ -433,6 +433,9 @@ class partial:
self._phcount = phcount
self._merger = merger
+ __class_getitem__ = classmethod(GenericAlias)
+
+
try:
from _functools import partial, Placeholder, _PlaceholderType
except ImportError:
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index ffd2adb..4a0252c 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -473,6 +473,12 @@ class TestPartial:
self.assertEqual(a.cmeth(3, b=4), ((1, A, 3), {'a': 2, 'b': 4}))
self.assertEqual(a.smeth(3, b=4), ((1, 3), {'a': 2, 'b': 4}))
+ def test_partial_genericalias(self):
+ alias = self.partial[int]
+ self.assertIs(alias.__origin__, self.partial)
+ self.assertEqual(alias.__args__, (int,))
+ self.assertEqual(alias.__parameters__, ())
+
@unittest.skipUnless(c_functools, 'requires the C _functools module')
class TestPartialC(TestPartial, unittest.TestCase):