diff --git a/music21/common/classTools.py b/music21/common/classTools.py index 18a8ee8d1d..2c4efd541e 100644 --- a/music21/common/classTools.py +++ b/music21/common/classTools.py @@ -40,7 +40,7 @@ def isInt(usrData: t.Any) -> t.TypeGuard[int]: return isinstance(usrData, int) and usrData is not True and usrData is not False -def isNum(usrData: t.Any) -> t.TypeGuard[Number]: +def isNum(usrData: t.Any) -> t.TypeGuard[numbers.Number]: ''' check if usrData is a number (float, int, long, Decimal), return boolean @@ -85,7 +85,7 @@ def isNum(usrData: t.Any) -> t.TypeGuard[Number]: return False -def isListLike(usrData: t.Any) -> bool: +def isListLike(usrData: t.Any) -> t.TypeGuard[list | tuple]: ''' Returns True if is a List or Tuple or their subclasses. @@ -145,7 +145,7 @@ def isIterable(usrData: t.Any) -> t.TypeGuard[Iterable]: return False -def holdsType(usrData: t.Any, checkType: type[_T]) -> TypeGuard[Collection[_T]]: +def holdsType(usrData: t.Any, checkType: type[_T]) -> t.TypeGuard[Collection[_T]]: ''' Returns True if usrData is a Collection of type checkType. diff --git a/music21/musicxml/xmlToM21.py b/music21/musicxml/xmlToM21.py index 48279fd386..14673afd63 100644 --- a/music21/musicxml/xmlToM21.py +++ b/music21/musicxml/xmlToM21.py @@ -4732,7 +4732,7 @@ def xmlBarline(self, mxBarline): # not complete # TODO: this should also filter by number (in theory.) - rbSpanners = self.spannerBundle.getByClass('RepeatBracket').getByCompleteStatus(False) + rbSpanners = self.spannerBundle.getByClass(spanner.RepeatBracket).getByCompleteStatus(False) # if we have no complete bracket objects, must start a new one if not rbSpanners: # create with this measure as the object diff --git a/music21/spanner.py b/music21/spanner.py index fcf028313d..b6ef7533d3 100644 --- a/music21/spanner.py +++ b/music21/spanner.py @@ -1348,7 +1348,6 @@ def _setNumber(self, value: int | str | Iterable[int]): # undefined. self.numberRange = [0] elif common.holdsType(value, int): - value = t.cast(Collection[int], value) # unnecessary, but not working in mypy 0.982 self.numberRange = [] # clear for x in value: self.numberRange.append(x) @@ -1364,7 +1363,7 @@ def _setNumber(self, value: int | str | Iterable[int]): one_number = int(one_letter_value.strip()) self.numberRange.append(one_number) elif value.isdigit(): - self.numberRange.append(int(value)) + self.numberRange = [int(value)] else: raise SpannerException(f'number for RepeatBracket must be a number, not {value!r}') elif common.isInt(value): diff --git a/music21/test/commonTest.py b/music21/test/commonTest.py index 944467114a..e8f2fb663d 100644 --- a/music21/test/commonTest.py +++ b/music21/test/commonTest.py @@ -76,12 +76,12 @@ def load_source(name: str, path: str) -> types.ModuleType: raise FileNotFoundError(f'No such file or directory: {path!r}') if name in sys.modules: module = sys.modules[name] - spec.loader.exec_module(module) else: module = importlib.util.module_from_spec(spec) if module is None: raise FileNotFoundError(f'No such file or directory: {path!r}') - spec.loader.exec_module(module) + sys.modules[name] = module + spec.loader.exec_module(module) return module @@ -424,7 +424,7 @@ def getModule(self, fp, restoreEnvironmentDefaults=False): with warnings.catch_warnings(): mod = load_source(name, fp) except Exception as excp: # pylint: disable=broad-except - environLocal.warn(['failed import:', fp, '\n', + environLocal.warn(['failed import:', name, '\t', fp, '\n', '\tEXCEPTION:', str(excp).strip()]) return None