|
28 | 28 | ''' |
29 | 29 | from __future__ import annotations |
30 | 30 |
|
31 | | -from collections import namedtuple |
32 | 31 | from math import inf as INFINITY |
33 | | -from music21 import exceptions21 |
| 32 | +import typing as t |
34 | 33 |
|
| 34 | +from music21.common.types import OffsetQL |
| 35 | +from music21 import exceptions21 |
35 | 36 |
|
36 | 37 | class SortingException(exceptions21.Music21Exception): |
37 | 38 | pass |
38 | 39 |
|
39 | 40 |
|
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): |
43 | 51 | ''' |
44 | 52 | Derived class of namedTuple which allows for comparisons with pure ints/fractions. |
45 | 53 |
|
@@ -255,9 +263,9 @@ def sub(self, other): |
255 | 263 | raise SortingException('Cannot add attributes from a different class') |
256 | 264 |
|
257 | 265 | 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 |
261 | 269 |
|
262 | 270 | return self.__class__(*outList) |
263 | 271 |
|
|
0 commit comments