Skip to content

Commit 2e1b44e

Browse files
committed
bpo-37645: use str(func) as fallback in _PyObject_FunctionStr()
1 parent 4c0c877 commit 2e1b44e

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

Doc/c-api/object.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,8 +201,8 @@ Object Protocol
201201
202202
Return a user-friendly string representation of the function-like object
203203
*func*. This returns ``func.__qualname__ + "()"`` if there is a
204-
``__qualname__`` attribute and ``type(func).__name__ + " object"``
205-
otherwise. Note that there is no check that *func* is actually callable.
204+
``__qualname__`` attribute and ``str(func)`` otherwise.
205+
Note that there is no check that *func* is actually callable.
206206
207207
.. versionadded:: 3.9
208208

Lib/test/test_extcall.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@
268268
>>> nothing(*h)
269269
Traceback (most recent call last):
270270
...
271-
TypeError: NoneType object argument after * must be an iterable, \
271+
TypeError: None argument after * must be an iterable, \
272272
not function
273273
274274
>>> h(**h)

Objects/object.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ def _PyObject_FunctionStr(f):
669669
try:
670670
return f.__qualname__ + "()"
671671
except Exception:
672-
return type(f).__name__ + " object"
672+
return str(f)
673673
*/
674674
PyObject *
675675
_PyObject_FunctionStr(PyObject *f)
@@ -686,7 +686,7 @@ _PyObject_FunctionStr(PyObject *f)
686686
return NULL;
687687
}
688688
PyErr_Clear();
689-
return PyUnicode_FromFormat("%.200s object", Py_TYPE(f)->tp_name);
689+
return PyObject_Str(f);
690690
}
691691

692692
/* For Python 3.0.1 and later, the old three-way comparison has been

0 commit comments

Comments
 (0)