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

Using __slots__ hides class variables #168

Closed
Nodd opened this issue Jun 3, 2023 · 1 comment · Fixed by #181
Closed

Using __slots__ hides class variables #168

Nodd opened this issue Jun 3, 2023 · 1 comment · Fixed by #181

Comments

@Nodd
Copy link
Contributor

Nodd commented Jun 3, 2023

If __slots__ is declared in a class, it takes precedence over everything, including class methods and variables. However __slots__ has an effect on instance attributes only, not class attributes.

The relevant lines is https://github.com/astropy/sphinx-automodapi/blob/0aad86aa90bcd7ab5b3004b732e21a3bd3d9de70/sphinx_automodapi/automodsumm.py#LL534C33-L549C33. Maybe names should also be filled with getattr(type(obj), '__dict__').keys() or something like that ?

@Nodd
Copy link
Contributor Author

Nodd commented Jun 3, 2023

After mode digging, I found that my suggestion was wrong. Actually I think that __slots__ should not be taken into account here, since the function applies to a class itself, so the class has a __dict__ even if __slots__ is declared.

Here is an example:

from pprint import pprint


class A:
    __slots__ = ("a", "b")

    def __init__(self):
        self.a = 0

    def func(self):
        """Documentation"""
        return 1


pprint(tuple(getattr(A, "__slots__")))  # ('a', 'b')
pprint(getattr(A, "__dict__").keys())  # dict_keys(['__module__', '__slots__', '__init__', 'func', 'a', 'b', '__doc__'])

Notice that the last line yields correctly func along with a and b.

kylefawcett pushed a commit to kylefawcett/sphinx-automodapi that referenced this issue Dec 19, 2023
kylefawcett pushed a commit to kylefawcett/sphinx-automodapi that referenced this issue Dec 19, 2023
kylefawcett pushed a commit to kylefawcett/sphinx-automodapi that referenced this issue Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant