Skip to content

Commit c2049e4

Browse files
JelleZijlstramiss-islington
authored andcommitted
pythongh-93021: Fix __text_signature__ for __get__ (pythonGH-93023)
Because of the way wrap_descr_get is written, the second argument to __get__ methods implemented through the wrapper is always optional. (cherry picked from commit 4e08fbc) Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
1 parent 9ab245f commit c2049e4

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

Lib/test/test_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,12 @@ def test_slot_wrapper_types(self):
599599
self.assertIsInstance(object.__lt__, types.WrapperDescriptorType)
600600
self.assertIsInstance(int.__lt__, types.WrapperDescriptorType)
601601

602+
def test_dunder_get_signature(self):
603+
sig = inspect.signature(object.__init__.__get__)
604+
self.assertEqual(list(sig.parameters), ["instance", "owner"])
605+
# gh-93021: Second parameter is optional
606+
self.assertIs(sig.parameters["owner"].default, None)
607+
602608
def test_method_wrapper_types(self):
603609
self.assertIsInstance(object().__init__, types.MethodWrapperType)
604610
self.assertIsInstance(object().__str__, types.MethodWrapperType)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the :attr:`__text_signature__` for :meth:`__get__` methods implemented
2+
in C. Patch by Jelle Zijlstra.

Objects/typeobject.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6907,7 +6907,7 @@ wrap_descr_get(PyObject *self, PyObject *args, void *wrapped)
69076907
obj = NULL;
69086908
if (type == Py_None)
69096909
type = NULL;
6910-
if (type == NULL &&obj == NULL) {
6910+
if (type == NULL && obj == NULL) {
69116911
PyErr_SetString(PyExc_TypeError,
69126912
"__get__(None, None) is invalid");
69136913
return NULL;
@@ -7950,7 +7950,7 @@ static slotdef slotdefs[] = {
79507950
TPSLOT("__next__", tp_iternext, slot_tp_iternext, wrap_next,
79517951
"__next__($self, /)\n--\n\nImplement next(self)."),
79527952
TPSLOT("__get__", tp_descr_get, slot_tp_descr_get, wrap_descr_get,
7953-
"__get__($self, instance, owner, /)\n--\n\nReturn an attribute of instance, which is of type owner."),
7953+
"__get__($self, instance, owner=None, /)\n--\n\nReturn an attribute of instance, which is of type owner."),
79547954
TPSLOT("__set__", tp_descr_set, slot_tp_descr_set, wrap_descr_set,
79557955
"__set__($self, instance, value, /)\n--\n\nSet an attribute of instance to value."),
79567956
TPSLOT("__delete__", tp_descr_set, slot_tp_descr_set,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy