Skip to content

Typing of "common" directory#1953

Merged
mscuthbert merged 7 commits into
masterfrom
typing_common
Jun 24, 2026
Merged

Typing of "common" directory#1953
mscuthbert merged 7 commits into
masterfrom
typing_common

Conversation

@mscuthbert

Copy link
Copy Markdown
Member

Annotate types in directory.

cacheMethod typing revealed but in roman.RomanNumeral.isMixture not self.isTriad to not self.isTriad()

Timer.clear() now resets so a cleared timer is immediately usable.

AI-assisted (Claude)

Annotate every previously-untyped function in music21/common/ (all 14
files) so the package passes mypy --disallow-untyped-defs
--disallow-incomplete-defs. Behavior-preserving refactors where needed
to make the new types honest: getMd5 isinstance narrowing, formatStr
typed internal list, and splitting the int/float variable reuse in
decimalToTuplet.

The more precise return types surfaced issues in callers, also fixed:
- findFormat/findFormatExtURL now return tuple[str|None, str|None];
  added None-guards in converter/__init__.py and scale/__init__.py.
- cacheMethod now returns Callable[..., Any], which revealed a latent
  bug in roman.RomanNumeral.isMixture: `not self.isTriad` referenced
  the bound method (always truthy) instead of calling it; fixed to
  isTriad()/isSeventh() to match every other call site.

Timer.clear() now resets _tStart = time.time() so _tStart stays a
plain float and a cleared timer is immediately usable.

AI-assisted (Claude)
optional_arg_decorator's fn and real_decorator's toBeDecorated, plus
deprecated's and cacheMethod's method, are now Callable[..., t.Any]
instead of t.Any (mypy permits __name__/__qualname__ reads on Callable;
the deprecated flag write keeps a narrow attr-defined ignore).

callInfo is now a _DeprecatedCallInfo TypedDict (calledAlready: bool,
message: str), and cacheMethod's inner instance is a _HasCache Protocol
exposing the ._cache dict it relies on.

AI-assisted (Claude)
cacheMethod is now Callable[Concatenate[S, P], R] -> the same, where S
is the receiver (bound to the _HasCache protocol) and P/R are the
method's params and return. inner's instance is that same S, so the
cache holder is tied to method's receiver rather than an unrelated
_HasCache, and decorated methods now expose their real return type
instead of Any. Full-package mypy stays clean.

deprecated's flag write uses method.__dict__['_isDeprecated'] = True,
which is type-clean (no attr-defined ignore, no setattr/B010).

AI-assisted (Claude)
@coveralls

coveralls commented Jun 24, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 93.137% (+0.005%) from 93.132% — typing_common into master

Add a comment noting the override returns a generator (not dict's
re-iterable ItemsView) on purpose, so the pairs follow the
most-common-first order of the overridden __iter__.

AI-assisted (Claude)
fn read too much like "function"; the pickleable test helpers _countN,
_countUnpacked, and the _customUpdate2 callback now use filename.

AI-assisted (Claude)
Instead of guarding ext is None only in the format-given branch (and
adding a defensive check in the URL branch), unindent the
`if ext is None: ext = '.txt'` so it covers both branches. ext is then
str for the _getDownloadFp call.

AI-assisted (Claude)
Add a case to testMixture using romanNumeralFromChord(Chord('C4 D4 E4'))
so the early `return False` in the not-triad-and-not-seventh guard is
exercised by the unit tests (it was the line whose missing parens this
branch fixed).

AI-assisted (Claude)
@mscuthbert mscuthbert merged commit accf688 into master Jun 24, 2026
7 checks passed
@mscuthbert mscuthbert deleted the typing_common branch June 24, 2026 21:09
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