Skip to content

Conversation

@mscuthbert
Copy link
Member

Improve typing for music21 based on issues uncovered in mypy 1.16.

Fix error in Interval.noteEnd = None -- setting noteStart, noteEnd, pitchStart, or pitchEnd to None raised exceptions

Improve typing for music21 based on issues uncovered in mypy 1.16.

Fix error in `Interval.noteEnd = None` -- setting noteStart, noteEnd, pitchStart, or pitchEnd to None raised exceptions

def solutionLegend(self, compress=False):
def solutionLegend(self, compress: bool = False) -> list[
list[str|list[tuple[int|str, str|None]]]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For complex types like this that you re-use, you can define a type alias. It might make it a bit clearer to understand when the same type is returned from different functions, or annotated on different variables.

https://docs.python.org/3/library/typing.html#typing.TypeAlias

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Andrew -- we use TypeAliases all over the place -- I'm leaving this in for now so that I can see that this is something to change/fix/standardize in the next not-backwards compatible version. There's no way if we had had Python typing when we wrote this code that anyone involved with music21 would have ever have let this come in. Next version will definitely be something cleaner like list[tuple[str, list[tuple[str, str]]]] and THAT will be worthy of a typealias.

@coveralls
Copy link

Coverage Status

coverage: 92.99% (-0.01%) from 93.0%
when pulling 772d4a8 on mypy-1.16
into 3ad399f on master.

@mscuthbert mscuthbert merged commit 4b39c04 into master Jun 19, 2025
7 of 8 checks passed
@mscuthbert mscuthbert deleted the mypy-1.16 branch June 19, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants