summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2014-08-20 23:41:57 (GMT)
committerBenjamin Peterson <benjamin@python.org>2014-08-20 23:41:57 (GMT)
commit48ad7c0b01de1be182c3894e1691861ccffb82ea (patch)
tree85fc3421bdd9d61bd0f1c9c9ce19971052c81a4d /Objects
parent2b7ccbda900f9fc697aac6fdb72841c83ca640eb (diff)
downloadcpython-48ad7c0b01de1be182c3894e1691861ccffb82ea.zip
cpython-48ad7c0b01de1be182c3894e1691861ccffb82ea.tar.gz
cpython-48ad7c0b01de1be182c3894e1691861ccffb82ea.tar.bz2
use __qualname__ to compute bound method repr (closes #21389)
Patch from Steven Barker.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/classobject.c43
1 files changed, 13 insertions, 30 deletions
diff --git a/Objects/classobject.c b/Objects/classobject.c
index 0c0bd47..07cb639 100644
--- a/Objects/classobject.c
+++ b/Objects/classobject.c
@@ -15,6 +15,7 @@ static int numfree = 0;
#endif
_Py_IDENTIFIER(__name__);
+_Py_IDENTIFIER(__qualname__);
PyObject *
PyMethod_Function(PyObject *im)
@@ -243,51 +244,33 @@ method_repr(PyMethodObject *a)
{
PyObject *self = a->im_self;
PyObject *func = a->im_func;
- PyObject *klass;
- PyObject *funcname = NULL ,*klassname = NULL, *result = NULL;
- char *defname = "?";
+ PyObject *funcname = NULL, *result = NULL;
+ const char *defname = "?";
- if (self == NULL) {
- PyErr_BadInternalCall();
- return NULL;
- }
- klass = (PyObject*)Py_TYPE(self);
-
- funcname = _PyObject_GetAttrId(func, &PyId___name__);
+ funcname = _PyObject_GetAttrId(func, &PyId___qualname__);
if (funcname == NULL) {
if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return NULL;
PyErr_Clear();
- }
- else if (!PyUnicode_Check(funcname)) {
- Py_DECREF(funcname);
- funcname = NULL;
- }
- if (klass == NULL)
- klassname = NULL;
- else {
- klassname = _PyObject_GetAttrId(klass, &PyId___name__);
- if (klassname == NULL) {
- if (!PyErr_ExceptionMatches(PyExc_AttributeError)) {
- Py_XDECREF(funcname);
+ funcname = _PyObject_GetAttrId(func, &PyId___name__);
+ if (funcname == NULL) {
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
return NULL;
- }
PyErr_Clear();
}
- else if (!PyUnicode_Check(klassname)) {
- Py_DECREF(klassname);
- klassname = NULL;
- }
+ }
+
+ if (funcname != NULL && !PyUnicode_Check(funcname)) {
+ Py_DECREF(funcname);
+ funcname = NULL;
}
/* XXX Shouldn't use repr()/%R here! */
- result = PyUnicode_FromFormat("<bound method %V.%V of %R>",
- klassname, defname,
+ result = PyUnicode_FromFormat("<bound method %V of %R>",
funcname, defname, self);
Py_XDECREF(funcname);
- Py_XDECREF(klassname);
return result;
}