Skip to content

Commit

Permalink
Implemented explicit slots on all selection classes.
Browse files Browse the repository at this point in the history
This helps satisfy GitHub #403.
  • Loading branch information
trevorbaca committed Aug 18, 2014
1 parent 1da629a commit 6cf4a5f
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 5 deletions.
7 changes: 6 additions & 1 deletion abjad/tools/selectiontools/ContiguousSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class ContiguousSelection(Selection):
r'''A time-contiguous selection of components.
'''

### CLASS VARIABLES ###

__slots__ = (
)

### INITIALIZER ###

def __init__(self, music=None):
Expand Down Expand Up @@ -721,4 +726,4 @@ def partition_by_durations_not_less_than(
fill='greater',
in_seconds=in_seconds,
overhang=overhang,
)
)
10 changes: 7 additions & 3 deletions abjad/tools/selectiontools/LogicalTie.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
from abjad.tools.topleveltools import attach
from abjad.tools.topleveltools import detach
from abjad.tools.topleveltools import mutate
from abjad.tools.selectiontools.ContiguousSelection \
import ContiguousSelection
from abjad.tools.selectiontools.ContiguousSelection import ContiguousSelection


class LogicalTie(ContiguousSelection):
Expand All @@ -26,6 +25,11 @@ class LogicalTie(ContiguousSelection):
'''

### CLASS VARIABLES ###

__slots__ = (
)

### PRIVATE METHODS ###

def _add_or_remove_notes_to_achieve_written_duration(
Expand Down Expand Up @@ -381,4 +385,4 @@ def to_tuplet(
#detach(spannertools.Tie, tuplet)

# return tuplet
return tuplet
return tuplet
21 changes: 21 additions & 0 deletions abjad/tools/selectiontools/Selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ def __getitem__(self, expr):
result = selection
return result

def __getstate__(self):
r'''Gets state of selection.
Returns dictionary.
'''
if hasattr(self, '__dict__'):
return vars(self)
state = {}
for class_ in type(self).__mro__:
for slot in getattr(class_, '__slots__', ()):
state[slot] = getattr(self, slot, None)
return state

def __hash__(self):
r'''Hashes selection.
Expand Down Expand Up @@ -160,6 +173,14 @@ def __repr__(self):
'''
return '{}{!r}'.format(type(self).__name__, self._music)

def __setstate__(self, state):
r'''Sets state of selection.
Returns none.
'''
for key, value in state.items():
setattr(self, key, value)

### PRIVATE PROPERTIES ###

@property
Expand Down
7 changes: 6 additions & 1 deletion abjad/tools/selectiontools/SliceSelection.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ class SliceSelection(ContiguousSelection):
'''

### CLASS VARIABLES ###

__slots__ = (
)

### INITIALIZER ###

# TODO: assert all are contiguous components in same parent
Expand Down Expand Up @@ -74,4 +79,4 @@ def _give_position_in_parent_to_container(self, container):
if parent is not None:
parent._music.__setitem__(slice(start, start), [container])
container._set_parent(parent)
self._set_parents(None)
self._set_parents(None)

0 comments on commit 6cf4a5f

Please sign in to comment.