Skip to content

Commit

Permalink
Typehinted abjad.Wrapper.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorbaca committed Apr 11, 2023
1 parent fb91535 commit f0ae90f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 18 deletions.
33 changes: 18 additions & 15 deletions abjad/bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,14 @@ class Wrapper:
def __init__(
self,
annotation: str | enum.Enum | None = None,
check_duplicate_indicator=False,
component=None,
# TODO: maybe remove check_duplicate_indicator and check automatically?
check_duplicate_indicator: bool = False,
component: _score.Component | None = None,
context: str | None = None,
deactivate: bool = False,
direction: _enums.Vertical | None = None,
indicator: typing.Any | None = None,
synthetic_offset: int | None = None,
synthetic_offset: _duration.Offset | None = None,
tag: _tag.Tag = _tag.Tag(),
) -> None:
assert not isinstance(indicator, type(self)), repr(indicator)
Expand All @@ -114,6 +115,9 @@ def __init__(
self._indicator = indicator
self._synthetic_offset: _duration.Offset | None
if synthetic_offset is not None:
assert isinstance(synthetic_offset, _duration.Offset), repr(
synthetic_offset
)
self._synthetic_offset = _duration.Offset(synthetic_offset)
else:
self._synthetic_offset = synthetic_offset
Expand Down Expand Up @@ -569,18 +573,18 @@ def leaked_start_offset(self) -> _duration.Offset:
>>> wrapper.start_offset, wrapper.leaked_start_offset
(Offset((0, 1)), Offset((1, 2)))
Returns offset.
"""
if self._synthetic_offset is not None:
return self._synthetic_offset
if isinstance(self.indicator, _tweaks.Bundle):
indicator = self.indicator.indicator
else:
indicator = self.indicator
assert isinstance(self.component, _score.Component)
if not getattr(indicator, "leak", False):
return self._component._get_timespan().start_offset
return self.component._get_timespan().start_offset
else:
return self._component._get_timespan().stop_offset
return self.component._get_timespan().stop_offset

@property
def start_offset(self) -> _duration.Offset:
Expand All @@ -590,16 +594,15 @@ def start_offset(self) -> _duration.Offset:
This is either the wrapper's synthetic offset or the start offset of the
wrapper's component.
"""
if self._synthetic_offset is not None:
return self._synthetic_offset
return self._component._get_timespan().start_offset
if self.synthetic_offset is not None:
return self.synthetic_offset
assert isinstance(self.component, _score.Component)
return self.component._get_timespan().start_offset

@property
def synthetic_offset(self):
def synthetic_offset(self) -> _duration.Offset | None:
"""
Gets synthetic offset.
Returns offset or none.
"""
return self._synthetic_offset

Expand Down Expand Up @@ -690,7 +693,7 @@ def attach(
deactivate: bool = False,
direction: _enums.Vertical | None = None,
do_not_test: bool = False,
synthetic_offset: int | None = None,
synthetic_offset: _duration.Offset | None = None,
tag: _tag.Tag | None = None,
wrapper: typing.Literal[True] = True,
) -> Wrapper:
Expand All @@ -707,7 +710,7 @@ def attach(
deactivate: bool = False,
direction: _enums.Vertical | None = None,
do_not_test: bool = False,
synthetic_offset: int | None = None,
synthetic_offset: _duration.Offset | None = None,
tag: _tag.Tag | None = None,
wrapper: typing.Literal[False],
) -> None:
Expand All @@ -723,7 +726,7 @@ def attach(
deactivate: bool = False,
direction: _enums.Vertical | None = None,
do_not_test: bool = False,
synthetic_offset: int | None = None,
synthetic_offset: _duration.Offset | None = None,
tag: _tag.Tag | None = None,
wrapper: bool = False,
) -> Wrapper | None:
Expand Down
3 changes: 2 additions & 1 deletion abjad/dynamic.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ class Dynamic:
.. container:: example
REGRESSION. Duplicate dynamics raise exception on attach:
REGRESSION. Duplicate dynamics raise exception on attach
when ``check_duplicate_indicator=True``:
>>> staff = abjad.Staff("c'4 d' e' f'")
>>> dynamic = abjad.Dynamic("p")
Expand Down
4 changes: 2 additions & 2 deletions abjad/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ def effective(
>>> abjad.attach(
... abjad.Clef("treble", hide=True),
... staff[0],
... synthetic_offset=-1,
... synthetic_offset=abjad.Offset(-1),
... )
>>> abjad.attach(abjad.Clef("alto"), staff[0])
>>> abjad.show(staff) # doctest: +SKIP
Expand Down Expand Up @@ -1211,7 +1211,7 @@ def effective(
>>> abjad.attach(
... abjad.Clef("alto", hide=True),
... staff[-1],
... synthetic_offset=1,
... synthetic_offset=abjad.Offset(1),
... )
>>> abjad.show(staff) # doctest: +SKIP
Expand Down

0 comments on commit f0ae90f

Please sign in to comment.