Typing of "common" directory#1953
Merged
Merged
Conversation
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)
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)
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.
Annotate types in directory.
cacheMethod typing revealed but in roman.RomanNumeral.isMixture
not self.isTriadtonot self.isTriad()Timer.clear() now resets so a cleared timer is immediately usable.
AI-assisted (Claude)