Skip to content

Commit 6f7e434

Browse files
authored
Merge branch 'main' into gh-128279
2 parents 72656c0 + 08a0728 commit 6f7e434

File tree

4 files changed

+16
-1
lines changed

4 files changed

+16
-1
lines changed

Doc/c-api/object.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,8 @@ Object Protocol
111111
.. note::
112112
113113
Exceptions that occur when this calls :meth:`~object.__getattr__` and
114-
:meth:`~object.__getattribute__` methods are silently ignored.
114+
:meth:`~object.__getattribute__` methods aren't propagated,
115+
but instead given to :func:`sys.unraisablehook`.
115116
For proper error handling, use :c:func:`PyObject_HasAttrWithError`,
116117
:c:func:`PyObject_GetOptionalAttr` or :c:func:`PyObject_GetAttr` instead.
117118

Lib/functools.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,9 @@ def __setstate__(self, state):
433433
self._phcount = phcount
434434
self._merger = merger
435435

436+
__class_getitem__ = classmethod(GenericAlias)
437+
438+
436439
try:
437440
from _functools import partial, Placeholder, _PlaceholderType
438441
except ImportError:

Lib/test/test_functools.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,12 @@ class A:
473473
self.assertEqual(a.cmeth(3, b=4), ((1, A, 3), {'a': 2, 'b': 4}))
474474
self.assertEqual(a.smeth(3, b=4), ((1, 3), {'a': 2, 'b': 4}))
475475

476+
def test_partial_genericalias(self):
477+
alias = self.partial[int]
478+
self.assertIs(alias.__origin__, self.partial)
479+
self.assertEqual(alias.__args__, (int,))
480+
self.assertEqual(alias.__parameters__, ())
481+
476482

477483
@unittest.skipUnless(c_functools, 'requires the C _functools module')
478484
class TestPartialC(TestPartial, unittest.TestCase):
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Add missing ``__class_getitem__`` method to the Python implementation of
2+
:func:`functools.partial`, to make it compatible with the C version. This is
3+
mainly relevant for alternative Python implementations like PyPy and
4+
GraalPy, because CPython will usually use the C-implementation of that
5+
function.

0 commit comments

Comments
 (0)