Skip to content

Commit 3a881af

Browse files
committed
lint and fraction
1 parent 685d0a3 commit 3a881af

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+149
-135
lines changed

documentation/source/developerReference/developerGuidelines.ipynb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,14 +145,17 @@
145145
"Conventions:\n",
146146
"\n",
147147
" - **Strings MUST be 'single-quoted', but \"double quotes\" are allowed internally**\n",
148-
" - This rule applies to triple quotes and doc strings also, contrary to PEP 257.\n",
149-
" - Docstrings must begin and end on their own lines. No one-line doc-strings or text\n",
148+
" - This rule applies to triple quotes and docstrings also, contrary to PEP 257.\n",
149+
" - Docstrings must begin and end on their own lines. No one-line docstrings or text\n",
150150
" immediately following the triple quotes.\n",
151151
" - When there is a hyphen or single quote in the string, double quotes should be used,\n",
152152
" not escaping/backslashing.\n",
153153
" - For long streams of TinyNotation or Lilypond code, which both use single quotes to indicate octave,\n",
154154
" triple single quotes around the string are better than double quotes. Internal whitespace\n",
155155
" rarely matters in those formats.\n",
156+
" - Before v10 concatenating strings without a plus sign was discouraged. I've changed my mind,\n",
157+
" and am \"letting Python be Python\" now especially when three or more lines are involved.\n",
158+
" However, use a + sign if concatenation is mixed with different comma-separated arguments.\n",
156159
" - Documentation should follow quoting in American English grammar when not\n",
157160
" discussing code. So for instance, a quotation in documentation is in double quotes.\n",
158161
" - Variable names:\n",
@@ -163,7 +166,8 @@
163166
" - Line lengths are capped at 100, but if approaching this limit, look for ways to avoid one-lining.\n",
164167
" - if it's easy to split your line into two which are both under 80 characters, do so.\n",
165168
" - Line continuation characters (`\\`) are not allowed; use open parentheses.\n",
166-
" - Prefer f-strings to `.format()`. The `%` interpolation is no longer allowed.\n",
169+
" - Greatly prefer f-strings to `.format()`. The `%` interpolation is no longer allowed.\n",
170+
" - `.format()` is only to be used when a repeated format string is involved.\n",
167171
" - Annotating types is **required** in new code, and encouraged to be added to older code.\n",
168172
" - e.g. `self.counter: int = 0` or `def makeNoises() -> list['noise.Noise']:`\n",
169173
" - The typing library should always be imported as `t`.\n",
@@ -193,7 +197,8 @@
193197
" manipulation of the original object. When `inPlace` is True, nothing should be returned\n",
194198
" (not true for `music21j` since passing through objects is so expected in JavaScript thanks\n",
195199
" to JQuery and other libraries). Use the `@overload` decorator to show how this parameter\n",
196-
" affects the return value -- Python makes this a bit hard, but see for instance, :meth:`~music21.stream.base.Stream.getElementsByClass` for an example of how to use this.\n",
200+
" affects the return value -- Python makes this a bit hard, but see for\n",
201+
" instance, :meth:`~music21.stream.base.Stream.getElementsByClass` for an example of how to use this.\n",
197202
" - Use descriptive pull request titles (rather than GitHub's default \"Update pitch.py\")\n",
198203
" - Do not have a PR title so long that it cannot be seen in one line. Simplify and\n",
199204
" rewrite and go into more detail in the description. I depend on skimming PR titles\n",

music21/abcFormat/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2621,7 +2621,7 @@ def tokenProcess(self) -> None:
26212621
else:
26222622
environLocal.printDebug(
26232623
['broken rhythm marker '
2624-
+ f'({token.src}) not positioned between two notes or chords'])
2624+
f'({token.src}) not positioned between two notes or chords'])
26252625

26262626
# need to update tuplets with currently active meter
26272627
if isinstance(token, ABCTuplet):
@@ -2698,7 +2698,7 @@ def tokenProcess(self) -> None:
26982698
if lastDefaultQL is None:
26992699
raise ABCHandlerException(
27002700
'no active default note length provided for note processing. '
2701-
+ f'tPrev: {tPrev}, token: {token}, tNext: {tNext}'
2701+
f'tPrev: {tPrev}, token: {token}, tNext: {tNext}'
27022702
)
27032703
token.activeDefaultQuarterLength = lastDefaultQL
27042704
token.activeKeySignature = lastKeySignature

music21/analysis/correlate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def pitchToDynamic(self, dataPoints=True):
131131
dstCheck = self.streamObj.recurse().getElementsByClass(objName)
132132
if not dstCheck:
133133
raise CorrelateException('cannot create correlation: an object '
134-
+ f'that is not found in the Stream: {objName}')
134+
f'that is not found in the Stream: {objName}')
135135

136136
self._findActive(objNameSrc, objNameDst)
137137

music21/analysis/reduction.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1095,7 +1095,7 @@ def _matchWeightedData(self, match, target):
10951095
dataMatch[2],
10961096
dataTarget[2],
10971097
msg=(f'for partId {partId}, entry {i}: '
1098-
+ f'should be {dataMatch[2]} <-> was {dataTarget[2]}')
1098+
f'should be {dataMatch[2]} <-> was {dataTarget[2]}')
10991099
)
11001100

11011101
def testPartReductionB(self, show=False):

music21/audioSearch/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def autocorrelationFunction(recordedSignal, recordSampleRateIn):
140140
# len(_missingImport) > 0:
141141
raise AudioSearchException(
142142
'Cannot run autocorrelationFunction without '
143-
+ f'numpy installed (scipy recommended). Missing {bmi}')
143+
f'numpy installed (scipy recommended). Missing {bmi}')
144144
import numpy
145145
convolve = None
146146
try:

music21/base.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ class Groups(list): # no need to inherit from slotted object
245245
def _validName(self, value: str) -> None:
246246
if not isinstance(value, str):
247247
raise exceptions21.GroupException('Only strings can be used as group names, '
248-
+ f'not {value!r}')
248+
f'not {value!r}')
249249
# if ' ' in value:
250250
# raise exceptions21.GroupException('Spaces are not allowed as group names')
251251

@@ -2110,7 +2110,7 @@ def contextSites(
21102110
memo.add(siteObj)
21112111
environLocal.printDebug(
21122112
f'looking in contextSites for {siteObj}'
2113-
+ f' with position {positionInStream.shortRepr()}')
2113+
f' with position {positionInStream.shortRepr()}')
21142114
for topLevel, inStreamPos, recurType in siteObj.contextSites(
21152115
callerFirst=callerFirst,
21162116
memo=memo,
@@ -2144,7 +2144,7 @@ def contextSites(
21442144
for derivedObject in topLevel.derivation.chain():
21452145
environLocal.printDebug(
21462146
'looking now in derivedObject, '
2147-
+ f'{derivedObject} with offsetAppend {offsetAppend}')
2147+
f'{derivedObject} with offsetAppend {offsetAppend}')
21482148
for derivedCsTuple in derivedObject.contextSites(
21492149
callerFirst=None,
21502150
memo=memo,
@@ -2441,7 +2441,7 @@ def _setActiveSite(self, site: stream.Stream|None):
24412441
except SitesException as se:
24422442
raise SitesException(
24432443
'activeSite cannot be set for '
2444-
+ f'object {self} not in the Stream {site}'
2444+
f'object {self} not in the Stream {site}'
24452445
) from se
24462446

24472447
self._activeSiteStoredOffset = storedOffset
@@ -3219,7 +3219,7 @@ def splitAtQuarterLength(
32193219
if quarterLength > self.duration.quarterLength:
32203220
raise DurationException(
32213221
f'cannot split a duration ({self.duration.quarterLength}) '
3222-
+ f'at this quarterLength ({quarterLength})'
3222+
f'at this quarterLength ({quarterLength})'
32233223
)
32243224

32253225
if retainOrigin is True:
@@ -3379,8 +3379,8 @@ def splitByQuarterLengths(
33793379
if opFrac(sum(quarterLengthList)) != self.duration.quarterLength:
33803380
raise Music21ObjectException(
33813381
'cannot split by quarter length list whose sum is not '
3382-
+ 'equal to the quarterLength duration of the source: '
3383-
+ f'{quarterLengthList}, {self.duration.quarterLength}'
3382+
'equal to the quarterLength duration of the source: '
3383+
f'{quarterLengthList}, {self.duration.quarterLength}'
33843384
)
33853385

33863386
# if nothing to do

music21/braille/basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def chordToBraille(music21Chord, descending=True, showOctave=True):
204204
except KeyError:
205205
environRules.warn(
206206
f'Accidental {currentPitch.accidental} of '
207-
+ f'chord {music21Chord} cannot be transcribed to braille.'
207+
f'chord {music21Chord} cannot be transcribed to braille.'
208208
)
209209
intervalDistance = interval.notesToGeneric(basePitch, currentPitch).undirected
210210
if intervalDistance > 8:
@@ -1115,7 +1115,7 @@ def timeSigToBraille(m21TimeSignature):
11151115
brailleSig = ''.join(timeSigTrans)
11161116
m21TimeSignature.editorial.brailleEnglish.append(
11171117
f'Time Signature {m21TimeSignature.numerator}/{m21TimeSignature.denominator} '
1118-
+ f'{brailleSig}'
1118+
f'{brailleSig}'
11191119
)
11201120
return brailleSig
11211121
except (BrailleBasicException, KeyError) as unused_error: # pragma: no cover

music21/braille/segment.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -442,9 +442,9 @@ def __str__(self):
442442
for k, g in zip(allKeys, allGroupings)
443443
)
444444
out = '\n'.join(['---begin segment---',
445-
name,
446-
allElementGroupings,
447-
'---end segment---'])
445+
name,
446+
allElementGroupings,
447+
'---end segment---'])
448448
return out
449449

450450
def transcribe(self):
@@ -1138,8 +1138,10 @@ def __str__(self):
11381138
else:
11391139
leftFull = ''
11401140
allPairs.append('\n'.join([rightFull, leftFull, '====\n']))
1141-
out = '\n'.join(['---begin grand segment---', name, ''.join(allPairs),
1142-
'---end grand segment---'])
1141+
out = '\n'.join(['---begin grand segment---',
1142+
name,
1143+
''.join(allPairs),
1144+
'---end grand segment---'])
11431145
return out
11441146

11451147
def yieldCombinedGroupingKeys(self):
@@ -1253,10 +1255,10 @@ def matchOther(thisKey_inner, otherKey):
12531255
# except ValueError as ve:
12541256
# raise BrailleSegmentException(
12551257
# 'Misaligned braille groupings: '
1256-
# + f'groupingKeyLeft was {gkLeft} '
1257-
# + f'groupingKeyRight was {gkRight} '
1258-
# + f'rightSegment was {rightSegment}, '
1259-
# + f'leftSegment was {leftSegment}'
1258+
# f'groupingKeyLeft was {gkLeft} '
1259+
# f'groupingKeyRight was {gkRight} '
1260+
# f'rightSegment was {rightSegment}, '
1261+
# f'leftSegment was {leftSegment}'
12601262
# ) from ve
12611263
#
12621264
# try:
@@ -2369,15 +2371,15 @@ def splitMeasure(music21Measure, beatDivisionOffset=0, useTimeSignature=None):
23692371
if abs(beatDivisionOffset) > len(ts.beatDivisionDurations):
23702372
raise BrailleSegmentException(
23712373
f'beatDivisionOffset {beatDivisionOffset} is outside '
2372-
+ f'of ts.beatDivisionDurations {ts.beatDivisionDurations}'
2374+
f'of ts.beatDivisionDurations {ts.beatDivisionDurations}'
23732375
)
23742376
duration_index = len(ts.beatDivisionDurations) - abs(beatDivisionOffset)
23752377
try:
23762378
offset += opFrac(ts.beatDivisionDurations[duration_index].quarterLength)
23772379
offset = opFrac(offset)
23782380
except IndexError:
23792381
environRules.warn('Problem in converting a time signature in measure '
2380-
+ f'{music21Measure.number}, offset may be wrong')
2382+
f'{music21Measure.number}, offset may be wrong')
23812383
bs = copy.deepcopy(ts.beatSequence)
23822384

23832385
numberOfPartitions = 2

music21/clef.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ def clefFromString(clefString, octaveShift=0) -> Clef:
858858

859859
if lineNum < 1 or lineNum > 5:
860860
raise ClefException('line number (second character) must be 1-5; do not use this '
861-
+ f'function for clefs on special staves such as {xnStr!r}')
861+
f'function for clefs on special staves such as {xnStr!r}')
862862

863863
clefObj: Clef
864864
if thisType in CLASS_FROM_TYPE:

music21/corpus/chorales.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ def _returnChorale(self, choraleIndex=None):
12731273
try:
12741274
nextIndex = self._currentIndex + 1
12751275
riemenschneiderName = ('bach/choraleAnalyses/'
1276-
+ f'riemenschneider{nextIndex:03d}.rntxt')
1276+
f'riemenschneider{nextIndex:03d}.rntxt')
12771277
analysis = corpus.parse(riemenschneiderName)
12781278
if analysis is not None:
12791279
chorale.insert(0, analysis.parts[0])
@@ -1582,7 +1582,7 @@ def currentNumber(self, value):
15821582
else:
15831583
raise BachException(
15841584
f'{value} does not correspond to a chorale in the '
1585-
+ f'{self.numberingSystem} numbering system'
1585+
f'{self.numberingSystem} numbering system'
15861586
)
15871587

15881588
elif self._iterationType == 'index':
@@ -1699,7 +1699,7 @@ def highestNumber(self, value):
16991699
else:
17001700
raise BachException(
17011701
f'{value} does not correspond to a chorale in the '
1702-
+ f'{self.numberingSystem} numbering system'
1702+
f'{self.numberingSystem} numbering system'
17031703
)
17041704

17051705
# - Return Type

0 commit comments

Comments
 (0)