Skip to content

Commit

Permalink
isNum type to Rational not Number
Browse files Browse the repository at this point in the history
  • Loading branch information
mscuthbert committed Oct 6, 2022
1 parent 0ea1ef5 commit bfb240e
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions music21/common/classTools.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ 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[numbers.Number]:
def isNum(usrData: t.Any) -> t.TypeGuard[numbers.Rational]:
'''
check if usrData is a number (float, int, long, Decimal),
return boolean
return boolean and if True casts the value as a Rational number
unlike `isinstance(usrData, Number)` does not return True for `True, False`.
unlike `isinstance(usrData, Rational)` does not return True for `True, False`.
Does not use `isinstance(usrData, Number)` which is 2-6 times slower
Does not use `isinstance(usrData, Rational)` which is 2-6 times slower
than calling this function (except in the case of Fraction, when
it's 6 times faster, but that's rarer). (6 times slower on Py3.4, now
only 2x slower in Python 3.10)
Expand Down
2 changes: 1 addition & 1 deletion music21/interval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1676,7 +1676,7 @@ def __init__(self,

if isinstance(generic, GenericInterval):
self.generic = generic
elif common.isNum(generic) or isinstance(generic, str):
elif common.isInt(generic) or isinstance(generic, str):
self.generic = GenericInterval(generic)
else: # pragma: no cover
# too rare to cover.
Expand Down
4 changes: 3 additions & 1 deletion music21/musicxml/xmlToM21.py
Original file line number Diff line number Diff line change
Expand Up @@ -4732,7 +4732,9 @@ def xmlBarline(self, mxBarline):
# not complete

# TODO: this should also filter by number (in theory.)
rbSpanners = self.spannerBundle.getByClass(spanner.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
Expand Down
2 changes: 1 addition & 1 deletion music21/note.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def number(self) -> int:

@number.setter
def number(self, value: int) -> None:
if not common.isNum(value):
if not common.isInt(value):
raise LyricException('Number best be number')
self._number = value

Expand Down
2 changes: 1 addition & 1 deletion music21/spanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
'''
from __future__ import annotations

from collections.abc import Collection, Sequence, Iterable
from collections.abc import Sequence, Iterable
import copy
import typing as t
import unittest
Expand Down

0 comments on commit bfb240e

Please sign in to comment.