Skip to content

Add typing to figuredBass#1940

Merged
mscuthbert merged 3 commits into
masterfrom
typing_figuredbass
Jun 21, 2026
Merged

Add typing to figuredBass#1940
mscuthbert merged 3 commits into
masterfrom
typing_figuredbass

Conversation

@mscuthbert

@mscuthbert mscuthbert commented Jun 21, 2026

Copy link
Copy Markdown
Member

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:

  • Make Jose Cabal-Ugaz's term Possibility (pitch-only tuple representing a possible vertical solution to a figured bass problem) be a unifying type, with a rest-allowing variant PossibilityWithRests
  • Fix bug in hiddenFifthsTable and hiddenOctavesTable where they would be switched to False after first read. (note: they are not used currently. See Misc - Post #1937 TODOs for FB #1938 .
  • Highlight issue with the removal of hashablePitch (2011!) and make a TODO to fix it in Misc - Post #1937 TODOs for FB #1938 PR
  • Add Music21ValueError(Music21Exception, ValueError) in exceptions21.py. unused - removed
  • roman.py: cast figuresNotationObj.numbers entries to int (Notation.numbers is now typed int|str|None).

AI-assisted (Claude)

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)
@coveralls

coveralls commented Jun 21, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 93.08% (-0.007%) from 93.087% — typing_figuredbass into master

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
@mscuthbert mscuthbert merged commit 6df42f0 into master Jun 21, 2026
6 of 7 checks passed
@mscuthbert mscuthbert deleted the typing_figuredbass branch June 21, 2026 17:38
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.

2 participants