mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
[3.13] gh-127537: Add __class_getitem__ to the python implementation of functools.partial (GH-127537) (#128281)
gh-127537: Add __class_getitem__ to the python implementation of functools.partial (GH-127537)
(cherry picked from commit 401bba6b58
)
Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
This commit is contained in:
parent
4f59f1d0d3
commit
1781525422
3 changed files with 14 additions and 0 deletions
|
@ -351,6 +351,9 @@ class partial:
|
|||
self.args = args
|
||||
self.keywords = kwds
|
||||
|
||||
__class_getitem__ = classmethod(GenericAlias)
|
||||
|
||||
|
||||
try:
|
||||
from _functools import partial
|
||||
except ImportError:
|
||||
|
|
|
@ -411,6 +411,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):
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
Add missing ``__class_getitem__`` method to the Python implementation of
|
||||
:func:`functools.partial`, to make it compatible with the C version. This is
|
||||
mainly relevant for alternative Python implementations like PyPy and
|
||||
GraalPy, because CPython will usually use the C-implementation of that
|
||||
function.
|
Loading…
Add table
Add a link
Reference in a new issue