Skip to content

Commit

Permalink
findConsecutiveNotes overload typing
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Aug 18, 2022
1 parent 90f481f commit 31ac8f2
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
4 changes: 1 addition & 3 deletions music21/features/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,10 +374,8 @@ def _getIntervalHistogram(self, algorithm='midi') -> t.List[int]:
skipChords=True,
skipGaps=True,
noNone=True)
for i, n in enumerate(post):
if t.TYPE_CHECKING:
assert isinstance(n, note.Note)

for i, n in enumerate(post):
if i < len(post) - 1: # if not last
iNext = i + 1
nNext = post[iNext]
Expand Down
66 changes: 56 additions & 10 deletions music21/stream/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9945,21 +9945,67 @@ def pitches(self) -> t.List[pitch.Pitch]:

# --------------------------------------------------------------------------
# interval routines
# TODO: override routine to show that if noNone is True that there is no None
# and if noNone and skipChords is True, then it can be typed as list[note.Note]

@overload
def findConsecutiveNotes(
self,
*,
skipRests: bool = False,
skipChords: t.Literal[False] = False,
skipUnisons: bool = False,
skipOctaves: bool = False,
skipGaps: bool = False,
getOverlaps: bool = False,
noNone: t.Literal[True],
**keywords
) -> t.List[note.NotRest]:
return []

@overload
def findConsecutiveNotes(
self,
*,
skipRests: bool = False,
skipChords: t.Literal[True],
skipUnisons: bool = False,
skipOctaves: bool = False,
skipGaps: bool = False,
getOverlaps: bool = False,
noNone: t.Literal[True],
**keywords
) -> t.List[note.Note]:
return []

@overload
def findConsecutiveNotes(
self,
*,
skipRests=False,
skipChords=False,
skipUnisons=False,
skipOctaves=False,
skipGaps=False,
getOverlaps=False,
noNone=False,
skipRests: bool = False,
skipChords: bool = False,
skipUnisons: bool = False,
skipOctaves: bool = False,
skipGaps: bool = False,
getOverlaps: bool = False,
noNone: t.Literal[False] = False,
**keywords
) -> t.List[t.Union[note.NotRest, None]]:
return []

def findConsecutiveNotes(
self,
*,
skipRests: bool = False,
skipChords: bool = False,
skipUnisons: bool = False,
skipOctaves: bool = False,
skipGaps: bool = False,
getOverlaps: bool = False,
noNone: bool = False,
**keywords
) -> t.Union[
t.List[t.Union[note.NotRest, None]],
t.List[note.NotRest],
t.List[note.Note],
]:
r'''
Returns a list of consecutive *pitched* Notes in a Stream.

Expand Down

0 comments on commit 31ac8f2

Please sign in to comment.