Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jdemeyer opened this issue Dec 31, 2018 · 2 comments · Fixed by #2773
Closed

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

jdemeyer opened this issue Dec 31, 2018 · 2 comments · Fixed by #2773

Comments

@jdemeyer
Copy link
Contributor

jdemeyer commented Dec 31, 2018

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.

@jdemeyer jdemeyer changed the title Python 2: __qualname__ on metaclass is wrong Python 2: __qualname__ is wrong Dec 31, 2018
@jdemeyer jdemeyer changed the title Python 2: __qualname__ is wrong Python 2: __qualname__ is wrong (when subclassed or on metaclass) Dec 31, 2018
@scoder
Copy link
Contributor

scoder commented 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).

Should we remove it only from classes in Py2?

@jdemeyer
Copy link
Contributor Author

Should we remove it only from classes in Py2?

I don't really have an opinion for functions. Maybe it's fine to keep __qualname__.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants