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.
When defining a Python class using Cython, the __qualname__ attribute is always set, even on Python 2. When this Cython-defined class is either subclassed or used as metaclass in pure Python code, that new class gets the wrong __qualname__ from Cython.
Examples:
# In Cython
class X(type): pass
# In Python
>>> class Y(X): pass
>>> Y.__qualname__
X
# In Python
>>> class Y(object): __metaclass__ = X
>>> Y.__qualname__
X
As you can see, we get a wrong __qualname__ in both cases. This confuses for example tools like Sphinx, where it produces incorrect output.
Since __qualname__ is useless on Python 2, I suggest to simply not set __qualname__ on Python 2. For Sphinx, not having a __qualname__ is fine, since it will simply use __name__ which is correct.
The text was updated successfully, but these errors were encountered:
jdemeyer
changed the title
Python 2: __qualname__ on metaclass is wrong
Python 2: __qualname__ is wrong
Dec 31, 2018
jdemeyer
changed the title
Python 2: __qualname__ is wrong
Python 2: __qualname__ is wrong (when subclassed or on metaclass)
Dec 31, 2018
Personally, I consider __qualname__ a useful debugging feature all by itself, so I'd prefer keeping it if/where possible. But the problem here is that Python doesn't override it for its own subtypes, so I understand that it gets in the way for classes. Functions should be ok (although, see #2562).
When defining a Python
class
using Cython, the__qualname__
attribute is always set, even on Python 2. When this Cython-defined class is either subclassed or used as metaclass in pure Python code, that new class gets the wrong__qualname__
from Cython.Examples:
As you can see, we get a wrong
__qualname__
in both cases. This confuses for example tools like Sphinx, where it produces incorrect output.Since
__qualname__
is useless on Python 2, I suggest to simply not set__qualname__
on Python 2. For Sphinx, not having a__qualname__
is fine, since it will simply use__name__
which is correct.The text was updated successfully, but these errors were encountered: