mirror of
https://github.com/python/cpython.git
synced 2025-08-10 11:58:39 +00:00
[3.12] gh-127537: Add __class_getitem__ to the python implementation of functools.partial (#127537) (#128282)
gh-127537: Add __class_getitem__ to the python implementation of functools.partial (#127537)
(cherry picked from commit 401bba6b58
)
Co-authored-by: CF Bolz-Tereick <cfbolz@gmx.de>
This commit is contained in:
parent
f699151c87
commit
82dbfbfec9
3 changed files with 15 additions and 0 deletions
|
@ -340,6 +340,9 @@ class partial:
|
|||
self.args = args
|
||||
self.keywords = kwds
|
||||
|
||||
__class_getitem__ = classmethod(GenericAlias)
|
||||
|
||||
|
||||
try:
|
||||
from _functools import partial
|
||||
except ImportError:
|
||||
|
|
|
@ -390,6 +390,13 @@ class TestPartial:
|
|||
f = self.partial(object)
|
||||
self.assertRaises(TypeError, f.__setstate__, BadSequence())
|
||||
|
||||
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):
|
||||
if c_functools:
|
||||
|
|
|
@ -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