Skip to content

Commit

Permalink
FIX: fixes __slots__ hides class variables astropy#168
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyle D Fawcett committed Dec 19, 2023
1 parent 07ce547 commit ed98751
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changes in sphinx-automodapi
0.17.0 (unreleased)
-------------------

- Fixes fixes ``__slots__`` hides class variables [#168]
- Minimum supported Python version is now 3.8. [#177]

0.16.0 (2023-08-17)
Expand Down
19 changes: 2 additions & 17 deletions sphinx_automodapi/automodsumm.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class members that are inherited from a base class. This value can be
.. _sphinx.ext.inheritance_diagram: http://sphinx-doc.org/latest/ext/inheritance.html
"""

import abc
import inspect
import os
import re
Expand Down Expand Up @@ -555,25 +554,11 @@ def get_members_class(obj, typ, include_public=[],
items = []

# using dir gets all of the attributes, including the elements
# from the base class, otherwise use __slots__ or __dict__
# from the base class, otherwise use __dict__
if include_base:
names = dir(obj)
else:
# Classes deriving from an ABC using the `abc` module will
# have an empty `__slots__` attribute in Python 3, unless
# other slots were declared along the inheritance chain. If
# the ABC-derived class has empty slots, we'll use the
# class `__dict__` instead.
declares_slots = (
hasattr(obj, '__slots__') and
not (issubclass(type(obj), abc.ABCMeta) and
len(obj.__slots__) == 0)
)

if declares_slots:
names = tuple(getattr(obj, '__slots__'))
else:
names = getattr(obj, '__dict__').keys()
names = getattr(obj, '__dict__').keys()

for name in names:
try:
Expand Down

0 comments on commit ed98751

Please sign in to comment.