Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions music21/common/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ def __call__(self) -> int:

# ------------------------------------------------------------------------------

_slotsByClass: dict[type, frozenset[str]] = {}


class SlottedObjectMixin:
r'''
Expand Down Expand Up @@ -223,9 +225,9 @@ def __setstate__(self, state: dict[str, t.Any]) -> None:
for slot, value in state.items():
setattr(self, slot, value)

def _getSlotsRecursive(self) -> set[str]:
def _getSlotsRecursive(self) -> frozenset[str]:
'''
Find all slots recursively.
Find all slots recursively. Cached per class.

A private attribute so as not to change the contents of inheriting
objects private interfaces:
Expand All @@ -250,10 +252,16 @@ def _getSlotsRecursive(self) -> set[str]:
['_editorial', '_style', 'direction', 'funkiness', 'groovability',
'id', 'independentAngle', 'number', 'type']
'''
try:
return _slotsByClass[type(self)]
except KeyError:
pass
slots: set[str] = set()
for cls in self.__class__.mro():
slots.update(getattr(cls, '__slots__', ()))
return slots
frozenSlots = frozenset(slots)
_slotsByClass[type(self)] = frozenSlots
return frozenSlots


class EqualSlottedObjectMixin(SlottedObjectMixin):
Expand Down
9 changes: 2 additions & 7 deletions music21/pitch.py
Original file line number Diff line number Diff line change
Expand Up @@ -1057,13 +1057,8 @@ class Accidental(prebase.ProtoM21Object, style.StyleMixin):

# INITIALIZER #

def __init__( # pylint: disable=super-init-not-called
self,
specifier: int|str|float = 'natural',
) -> None:
# StyleMixin.__init__, inlined for speed; keep in sync
self._style = None
self._editorial = None
def __init__(self, specifier: int|str|float = 'natural') -> None:
super().__init__()
# managed by properties
self._displayType = 'normal'
# normal, always, never, if-absolutely-necessary,
Expand Down
Loading