Skip to content

Typing tree.spans / tighten constructors#1960

Merged
mscuthbert merged 1 commit into
masterfrom
type-spans
Jun 29, 2026
Merged

Typing tree.spans / tighten constructors#1960
mscuthbert merged 1 commit into
masterfrom
type-spans

Conversation

@mscuthbert

Copy link
Copy Markdown
Member

Preparing to use tree.verticality more, we need better typing for tree.spans.TimeSpan and its derived classes, ElementTimespan and PitchedTimespan.

  • Timespan offset/endTime are required OffsetQL (no None or -inf/inf defaults).
  • ElementTimespan requires an element (base.Music21Object) at construction.
  • PitchedTimespan narrows element to note.GeneralNote -- this violates LSP but it's too entrenched to work around.
  • parentage defaults to ().

AI-assisted (Claude).

Annotate every signature in spans.py and remove the None-stripping casts by
making the underlying types honest:
- Timespan offset/endTime are required OffsetQL (no None, no -inf/inf defaults).
- ElementTimespan requires an element (base.Music21Object); PitchedTimespan
  narrows element to note.GeneralNote so .pitches needs no cast.
- parentage defaults to () (non-Optional).
- Reorder ElementTimespan/PitchedTimespan __init__ and new() to match the parent
  Timespan(offset, endTime): (offset, endTime, element, *, parentOffset=None,
  parentEndTime=None, parentage=()); new() is keyword-only, removing the
  prior LSP # type: ignore[override].
- Three spans.py doctests updated to the new positional order; no construction
  outside music21/tree/ was affected.

* Changed in v11: order of arguments matches parent class. (ElementTimespan,
  PitchedTimespan)

mypy/ruff/pylint(10.00)/pytest all green. First module of the tree typing
prerequisite (2A) of the Verticality plan.

AI-assisted (Claude).
@coveralls

Copy link
Copy Markdown

Coverage Status

coverage: 93.295%. remained the same — type-spans into master

@mscuthbert mscuthbert merged commit ab82f89 into master Jun 29, 2026
7 checks passed
@mscuthbert mscuthbert deleted the type-spans branch June 29, 2026 06:25
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