Skip to content

Commit 488c358

Browse files
authored
Merge pull request #1827 from cuthbertLab/typed_sort_tuple
sortTuple gets typing
2 parents 3a04fb6 + a5579d2 commit 488c358

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

music21/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
'''
5151
from __future__ import annotations
5252

53-
__version__ = '10.0.1b1'
53+
__version__ = '10.0.1b2'
5454

5555
def get_version_tuple(vv):
5656
v = vv.split('.')

music21/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<class 'music21.base.Music21Object'>
2828
2929
>>> music21.VERSION_STR
30-
'10.0.1b1'
30+
'10.0.1b2'
3131
3232
Alternatively, after doing a complete import, these classes are available
3333
under the module "base":

music21/sorting.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,26 @@
2828
'''
2929
from __future__ import annotations
3030

31-
from collections import namedtuple
3231
from math import inf as INFINITY
33-
from music21 import exceptions21
32+
import typing as t
3433

34+
from music21.common.types import OffsetQL
35+
from music21 import exceptions21
3536

3637
class SortingException(exceptions21.Music21Exception):
3738
pass
3839

3940

40-
class SortTuple(namedtuple('SortTuple', (
41-
'atEnd', 'offset', 'priority', 'classSortOrder', 'isNotGrace', 'insertIndex'
42-
))):
41+
_SortTupleBase = t.NamedTuple('SortTuple', [ # type: ignore[name-match]
42+
('atEnd', int),
43+
('offset', OffsetQL),
44+
('priority', int),
45+
('classSortOrder', int),
46+
('isNotGrace', int),
47+
('insertIndex', int),
48+
])
49+
50+
class SortTuple(_SortTupleBase):
4351
'''
4452
Derived class of namedTuple which allows for comparisons with pure ints/fractions.
4553
@@ -255,9 +263,9 @@ def sub(self, other):
255263
raise SortingException('Cannot add attributes from a different class')
256264

257265
outList = [min(getattr(self, attr), getattr(other, attr))
258-
if attr in ('atEnd', 'isNotGrace')
259-
else (getattr(self, attr) - getattr(other, attr))
260-
for attr in self._fields] # _fields are the namedtuple attributes
266+
if attr in ('atEnd', 'isNotGrace')
267+
else (getattr(self, attr) - getattr(other, attr))
268+
for attr in self._fields] # _fields are the namedtuple attributes
261269

262270
return self.__class__(*outList)
263271

0 commit comments

Comments
 (0)