Add typing to figuredBass#1940
Merged
Merged
Conversation
Adds parameter/return type annotations across the figuredBass package (possibility, segment, resolution, realizer, checker, notation, harmony, rules, realizerScale, examples). Split into its own PR for review separate from the scale/search/romanText typing. Highlights: - Keep Jose's domain term Possibility (pitch-only tuple), single-sourced in possibility.py; checker's rest-allowing variant is PossibilityWithRests (tuple[Pitch | Literal['RT'], ...]). - checker.possibilityIsPitchOnlyOrRaise() raises on a rest rather than silently returning [] (a false 'no violations'). - Add Music21ValueError(Music21Exception, ValueError) in exceptions21.py. - roman.py: cast figuresNotationObj.numbers entries to int (Notation.numbers is now typed int|str|None). Entirely AI written (AI-assisted, Claude). AI-assisted (Claude)
In checkConsecutivePossibilities the colored note came from .first(), which returns Music21Object|None; casting it to base.Music21Object only deferred the failure to a cryptic 'None has no attribute style'. Raise Music21Exception explicitly if the note is missing. Also drop the redundant cast in checkSinglePossibilities (its element comes from [0], never None) and remove the now-unused base import. AI-assisted (Claude)
The original checks already worked with rests (voiceCrossing skipped via
hasattr('ps'); the parallel/hidden checks filtered them via try/except
AttributeError). Restore that: the five checks now zip(possibA, possibB)
directly and use explicit isinstance(x, pitch.Pitch) / continue, so a rest
('RT') in a part is skipped rather than raising. Drops possibility.partPairs
(too tightly typed to pitch-only) and the possibilityIsPitchOnlyOrRaise helper.
Also: generalNoteToPitch uses isinstance(note.Note) instead of .isNote + cast
(note moved to a runtime import; no circular import), and Music21ValueError is
removed from exceptions21.py since nothing uses it now.
AI-assisted (Claude)
This was referenced Jun 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds parameter/return type annotations across the figuredBass package (possibility, segment, resolution, realizer, checker, notation, harmony, rules, realizerScale, examples). Split into its own PR from #1937 for review separate from the scale/search/romanText typing.
Highlights:
Add Music21ValueError(Music21Exception, ValueError) in exceptions21.py.unused - removedAI-assisted (Claude)