Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@

# PRs and Issues

- GitHub runs PR checks against your branch **merged with the latest `master`**, not the
branch alone. So before opening a PR (or pushing updates to one), merge the latest commits
from `master` into the branch — unless told otherwise, or when updating an older version
branch such as `m21_9`. When a CI check fails but passes locally, "is my branch behind
`master`?" should be one of the first things to check: fetch and merge `master`, then the
newer types/code on `master` will reproduce the failure locally.
- All PRs and Issues need to be declared AI-assisted.
- 10 or more lines of code written by an agent needs to be declared as AI-assisted in the docstring.
Humans can remove and should remove this note when they do a review.
Expand Down
4 changes: 2 additions & 2 deletions music21/features/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class Feature:
And that's it! FeatureExtractors are much more interesting.
'''

def __init__(self):
def __init__(self) -> None:
# these values will be filled by the extractor
self.dimensions: int = 1 # number of dimensions
# data storage; possibly use numpy array
Expand All @@ -97,7 +97,7 @@ def __init__(self):
self.isSequential = None # True or False
self.discrete = None # is discrete or continuous

def _getVectors(self):
def _getVectors(self) -> list[int|float]:
'''
Prepare a vector of appropriate size and return
'''
Expand Down
75 changes: 46 additions & 29 deletions music21/romanText/clercqTemperley.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,8 @@ class CTSong(prebase.ProtoM21Object):
''',
}

def __init__(self, textFile: str|pathlib.Path = '', **keywords):
self._title = None
def __init__(self, textFile: str|pathlib.Path = '', **keywords: t.Any) -> None:
self._title: str|None = None
self.text = ''
self.lines: list[str] = []
# Dictionary of all component rules of the type CTRule
Expand All @@ -345,27 +345,27 @@ def __init__(self, textFile: str|pathlib.Path = '', **keywords):
self.tsList: list[meter.TimeSignature] = []

self._partObj = stream.Part()
self.year = None
self.year: int|None = None

self._homeTimeSig = None
self._homeKey = None
self._homeTimeSig: meter.TimeSignature|None = None
self._homeKey: key.Key|None = None

self.labelRomanNumerals = True
self.labelSubsectionsOnScore = True

for kw in keywords:
for kw, value in keywords.items():
if kw == 'title':
self._title = kw
if kw == 'year':
self.year = kw
self._title = value
elif kw == 'year':
self.year = value

self.parse(textFile)

def _reprInternal(self):
def _reprInternal(self) -> str:
return f'title={self.title!r} year={self.year}'

# --------------------------------------------------------------------------
def parse(self, textFile: str|pathlib.Path):
def parse(self, textFile: str|pathlib.Path) -> None:
'''
Called when a CTSong is created by passing a string or filename;
in the second case, it opens the file
Expand Down Expand Up @@ -412,7 +412,7 @@ def parse(self, textFile: str|pathlib.Path):
self.text = pieceString

@property
def title(self):
def title(self) -> str|None:
'''
Get or set the title of the CTSong. If not specified
explicitly but the clercq-Temperley text exists,
Expand All @@ -432,7 +432,7 @@ def title(self):
return title

@property
def comments(self):
def comments(self) -> list[list[str]]:
r"""
Get the comments list of all CTRule objects.

Expand All @@ -459,7 +459,7 @@ def comments(self):
>>> s.comments
[['A wonderful shaker melody'], ['Vr:', 'incomplete verse'], ['S:', 'Not quite finished!']]
"""
comments = []
comments: list[list[str]] = []
for line in self.lines[1:]:
if '%' in line:
if line.split()[0].endswith(':'):
Expand All @@ -470,7 +470,7 @@ def comments(self):
return comments

@property
def rules(self):
def rules(self) -> dict[str, CTRule]:
# noinspection PyShadowingNames
'''
Get the rules of a CTSong. the Rules is an OrderedDict of
Expand Down Expand Up @@ -515,7 +515,7 @@ def rules(self):
return self._rules

@property
def homeTimeSig(self):
def homeTimeSig(self) -> meter.TimeSignature|None:
r'''
gets the initial, or 'home', time signature in a song by looking at the 'S' substring
and returning the provided time signature. If not present, returns a default music21
Expand Down Expand Up @@ -551,7 +551,7 @@ def homeTimeSig(self):
return self._homeTimeSig

@property
def homeKey(self):
def homeKey(self) -> key.Key|None:
'''
gets the initial, or 'home', Key by looking at the music text and locating
the key signature at the start of the S: rule.
Expand Down Expand Up @@ -580,7 +580,11 @@ def homeKey(self):
pass
return self._homeKey

def toPart(self, labelRomanNumerals=True, labelSubsectionsOnScore=True) -> stream.Part:
def toPart(
self,
labelRomanNumerals: bool = True,
labelSubsectionsOnScore: bool = True,
) -> stream.Part:
# noinspection PyShadowingNames
'''
creates a Part object out of a from CTSong and also creates CTRule objects in the process,
Expand Down Expand Up @@ -611,7 +615,11 @@ def toPart(self, labelRomanNumerals=True, labelSubsectionsOnScore=True) -> strea
self._partObj = partObj
return partObj

def toScore(self, labelRomanNumerals=True, labelSubsectionsOnScore=True) -> stream.Part:
def toScore(
self,
labelRomanNumerals: bool = True,
labelSubsectionsOnScore: bool = True,
) -> stream.Part:
'''
DEPRECATED: use .toPart() instead. This method will be removed in v.10
'''
Expand Down Expand Up @@ -642,8 +650,8 @@ class CTRule(prebase.ProtoM21Object):
SPLITMEASURES = re.compile(r'(\|\*?\d*)')
REPETITION = re.compile(r'\*(\d+)')

def __init__(self, text='', parent: CTSong|None = None):
self._parent = None
def __init__(self, text: str = '', parent: CTSong|None = None) -> None:
self._parent: t.Any = None
if parent is not None:
self.parent = parent

Expand All @@ -660,14 +668,14 @@ def __init__(self, text='', parent: CTSong|None = None):
self._lastChordIsInSameMeasure: bool = False


def _reprInternal(self):
def _reprInternal(self) -> str:
return f'text={self.text!r}'

# --------------------------------------------------------------------------
def _getParent(self):
def _getParent(self) -> CTSong|None:
return common.unwrapWeakref(self._parent)

def _setParent(self, parent):
def _setParent(self, parent: CTSong) -> None:
self._parent = common.wrapWeakref(parent)

parent = property(_getParent, _setParent, doc=r'''
Expand Down Expand Up @@ -1002,7 +1010,7 @@ def fixupChordAtom(self, atom: str) -> str:
def _setMusicText(self, value: str) -> None:
self._musicText = str(value)

def _getMusicText(self):
def _getMusicText(self) -> str:
if self._musicText:
return self._musicText

Expand Down Expand Up @@ -1073,7 +1081,7 @@ def _setLHS(self, value: str) -> None:
''')

@property
def sectionName(self):
def sectionName(self) -> str:
'''
Returns the expanded version of the Left-hand side (LHS) such as
Introduction, Verse, etc. if
Expand Down Expand Up @@ -1114,20 +1122,29 @@ def sectionName(self):

# ------------------------------------------------------------------------------
class Test(unittest.TestCase):
pass

def testTitleAndYear(self) -> None:
'''
The title and year keywords passed to CTSong should be stored on the
object itself (rather than the keyword names being stored by mistake).
'''
s = CTSong(BlitzkriegBopCT, title="Someday We'll Be Together", year=1969)
# the title keyword overrides the "% Blitzkrieg Bop" comment in the text
self.assertEqual(s.title, "Someday We'll Be Together")
self.assertEqual(s.year, 1969)


class TestExternal(unittest.TestCase):
show = True

def testB(self):
def testB(self) -> None:
from music21.romanText import clercqTemperley
s = clercqTemperley.CTSong(BlitzkriegBopCT)
partObj = s.toPart()
if self.show:
partObj.show()

def x_testA(self):
def x_testA(self) -> None:
pass
# from music21.romanText import clercqTemperley
#
Expand Down
Loading
Loading