Skip to content

Python 2: __qualname__ is wrong (when subclassed or on metaclass) #2772

@jdemeyer

Description

@jdemeyer

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions