You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
__qualname__ is not present on builtin methods and functions #57786
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2011-12-23.11:42:04.400>created_at=<Date2011-12-11.04:27:04.637>labels= ['interpreter-core', 'type-bug']
title='__qualname__ is not present on builtin methods and functions'updated_at=<Date2011-12-23.11:42:04.399>user='https://github.com/meadori'
I was recently experimenting with the new PEP-3155 '__qualname__ implementation and noticed that '__qualname__' is not present on builtin methods and functions:
[meadori@motherbrain cpython]$ ./python
Python 3.3.0a0 (default:aab45b904141+, Dec 10 2011, 14:53:54)
[GCC 4.6.2 20111027 (Red Hat 4.6.2-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> max.__qualname__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'builtin_function_or_method' object has no attribute '__qualname__'
>>> str.strip.__qualname__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'method_descriptor' object has no attribute '__qualname__'
I already have a patch for the descriptor types which lazily calculates the __qualname__. However test.test_sys also needs fixing because it tests that these types have expected sizes.
I have not got round to builtin_function_or_method though.
sbt commented on Dec 11, 2011
sbtmannequin
Mannequin
More actions
Updated patch which fixes test.test_sys.SizeofTest. (It also adds __qualname__ to member descriptors and getset descriptors.)
The patch should add some tests for the added functionality (I'm not sure where, but perhaps test_descr is a good location).
Also, just a nitpick, you can use _PyObject_GetAttrId and the _Py_IDENTIFIER macro instead of interning the "__qualname__" string yourself.
Note that extension (non-builtin) types will need to have their __qualname__ fixed before their methods' __qualname__ is usable:
>>> collections.deque.__qualname__
'deque'
sbt commented on Dec 11, 2011
sbtmannequin
Mannequin
More actions
Note that extension (non-builtin) types will need to have their
__qualname__ fixed before their methods' __qualname__ is usable:
>>> collections.deque.__qualname__
'deque'
I'm confused. Isn't that the expected behaviour? Since the deque class is not nested inside another class or function, __qualname__ should be the same as __name__, shouldn't it?
> Note that extension (non-builtin) types will need to have their
> __qualname__ fixed before their methods' __qualname__ is usable:
>
> >>> collections.deque.__qualname__
> 'deque'
I'm confused. Isn't that the expected behaviour? Since the deque
class is not nested inside another class or function, __qualname__
should be the same as __name__, shouldn't it?
Uh, yes, my bad.
sbt commented on Dec 12, 2011
sbtmannequin
Mannequin
More actions
New version of the patch with tests and using _Py_IDENTIFIER.
apparently you forgot to add BuiltinFunctionPropertiesTest in test_main()?
a static method keeps a reference to the type: I think it's ok, although I'm not sure about the consequences (Guido, would you have an idea?)
about "XXX Note that it is not possible to use __qualname__ to distinguish a builtin bound instance method from its unbound equivalent", I don't think it's a problem. People can e.g. check for __self__:
>>> list.append.__self__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'method_descriptor' object has no attribute '__self__'
>>> list().append.__self__
[]
sbt commented on Dec 12, 2011
sbtmannequin
Mannequin
More actions
apparently you forgot to add BuiltinFunctionPropertiesTest in
test_main()?
Yes. Fixed.
a static method keeps a reference to the type: I think it's ok, although
I'm not sure about the consequences (Guido, would you have an idea?)
Interestingly, in the stdlib METH_STATIC is only used by (str|bytes|bytearray).maketrans and _multiprocessing.win32.*.
Thanks for the patch. Since you modified PyCFunction_GET_SELF to return NULL for static methods, why not simply use it instead of manually looking up the flags in several places?
Activity
meadori commentedon Dec 11, 2011
I was recently experimenting with the new PEP-3155 '__qualname__ implementation and noticed that '__qualname__' is not present on builtin methods and functions:
I will work up a patch.
sbt commentedon Dec 11, 2011
I already have a patch for the descriptor types which lazily calculates the __qualname__. However test.test_sys also needs fixing because it tests that these types have expected sizes.
I have not got round to builtin_function_or_method though.
sbt commentedon Dec 11, 2011
Updated patch which fixes test.test_sys.SizeofTest. (It also adds __qualname__ to member descriptors and getset descriptors.)
pitrou commentedon Dec 11, 2011
The patch should add some tests for the added functionality (I'm not sure where, but perhaps test_descr is a good location).
Also, just a nitpick, you can use _PyObject_GetAttrId and the _Py_IDENTIFIER macro instead of interning the "__qualname__" string yourself.
Note that extension (non-builtin) types will need to have their __qualname__ fixed before their methods' __qualname__ is usable:
>>> collections.deque.__qualname__ 'deque'sbt commentedon Dec 11, 2011
I'm confused. Isn't that the expected behaviour? Since the deque class is not nested inside another class or function, __qualname__ should be the same as __name__, shouldn't it?
pitrou commentedon Dec 11, 2011
Uh, yes, my bad.
sbt commentedon Dec 12, 2011
New version of the patch with tests and using _Py_IDENTIFIER.
pitrou commentedon Dec 12, 2011
Ok, a couple of further (minor) issues:
Otherwise, looks good, thank you.
sbt commentedon Dec 12, 2011
Patch which add __qualname__ to builtin_function_or_method. Note that I had to make a builtin staticmethod have __self__ be the type instead of None.
sbt commentedon Dec 12, 2011
Fixed. (I suspect, though, that caching the value of __qualname__ is an unnecessary optimisation.)
python-dev commentedon Dec 12, 2011
New changeset 24238e89f938 by Antoine Pitrou in branch 'default':
Issue bpo-13577: various kinds of descriptors now have a __qualname__ attribute.
http://hg.python.org/cpython/rev/24238e89f938
pitrou commentedon Dec 12, 2011
About method_qualname.patch:
apparently you forgot to add BuiltinFunctionPropertiesTest in test_main()?
a static method keeps a reference to the type: I think it's ok, although I'm not sure about the consequences (Guido, would you have an idea?)
about "XXX Note that it is not possible to use __qualname__ to distinguish a builtin bound instance method from its unbound equivalent", I don't think it's a problem. People can e.g. check for __self__:
sbt commentedon Dec 12, 2011
Yes. Fixed.
Interestingly, in the stdlib METH_STATIC is only used by (str|bytes|bytearray).maketrans and _multiprocessing.win32.*.
meadori commentedon Dec 13, 2011
For the most part this looks OK, but I am not sure about this hunk:
That may be a breaking change as existing code may rely on the 'None' behavior. In
fact, this causes a unit test to fail with the patch applied:
sbt, have you been running the test suite before submitting patches? If not, then
please do.
sbt commentedon Dec 13, 2011
I ran it after I submitted. Sorry.
Here is another patch. It also makes sure that __self__ is reported as None when METH_STATIC.
pitrou commentedon Dec 21, 2011
Thanks for the patch. Since you modified PyCFunction_GET_SELF to return NULL for static methods, why not simply use it instead of manually looking up the flags in several places?
I'm talking about the following changes:
[...]
[...]
+ PyObject *self = flags & METH_STATIC ? NULL :
+ _PyCFunction_GET_RAW_SELF(func);
Unless you demonstrate there's a significant performance improvement in this style, we should really favour the simpler style.
sbt commentedon Dec 21, 2011
A simplified patch getting rid of _PyCFunction_GET_RAW_SELF().
python-dev commentedon Dec 23, 2011
New changeset 7a7b698f6f21 by Antoine Pitrou in branch 'default':
Issue bpo-13577: Built-in methods and functions now have a __qualname__.
http://hg.python.org/cpython/rev/7a7b698f6f21
pitrou commentedon Dec 23, 2011
The patch is committed, thank you!