Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove *arguments where not used #1394

Merged
merged 37 commits into from
Aug 18, 2022
Merged
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
e63e8ba
Explicit Keywords on all music21 objects
mscuthbert Aug 14, 2022
4a72f9f
Tuplet
mscuthbert Aug 14, 2022
6a1785d
few fixes. More needed
mscuthbert Aug 14, 2022
f902683
update some types
mscuthbert Aug 14, 2022
41b9bc2
lint,mypy,test
mscuthbert Aug 15, 2022
44aad43
note -- finished
mscuthbert Aug 15, 2022
89cfd1f
Stream; and fix previous typing
mscuthbert Aug 15, 2022
48958b1
fix mypy
mscuthbert Aug 15, 2022
db59588
fixup chordBase; lint
mscuthbert Aug 15, 2022
689e1ee
lint and mypy
mscuthbert Aug 15, 2022
81f3d5a
discrete analysis
mscuthbert Aug 15, 2022
3c92d8c
fix lints
mscuthbert Aug 16, 2022
6c4de9a
lint, mypy, flake
mscuthbert Aug 16, 2022
6723a1d
Variant takes only one arg
mscuthbert Aug 16, 2022
a627b56
kwargs -> keywords throughout
mscuthbert Aug 16, 2022
25228ea
midi realtime, etc.
mscuthbert Aug 16, 2022
a510697
lint, mypy
mscuthbert Aug 16, 2022
5a2ed20
Chorales, Date primitives, RepeatBracket
mscuthbert Aug 16, 2022
ba6f1e4
lint
mscuthbert Aug 16, 2022
38d103a
more metadata DatePrimitive work
mscuthbert Aug 16, 2022
dbeac11
layout. Remove chorales warnings; separate issue
mscuthbert Aug 16, 2022
29841b6
layout import annotations
mscuthbert Aug 16, 2022
5376b5a
Remove *arguments where not used
mscuthbert Aug 16, 2022
5327e26
fix substitution principle; sigh.
mscuthbert Aug 16, 2022
d2482fc
Remove more *args
mscuthbert Aug 16, 2022
ee330ba
fix metadata tests pinned to 8.0.0a9
mscuthbert Aug 16, 2022
20087f0
spanner star args
mscuthbert Aug 16, 2022
4cb3228
lint and flake
mscuthbert Aug 16, 2022
2377900
Merge branch 'explicit-keywords' into remove-star-args
mscuthbert Aug 16, 2022
5e78fde
fix all but bugs going other way
mscuthbert Aug 17, 2022
88978c6
Converting Interval to use Pitches not Note
mscuthbert Aug 17, 2022
ac2745b
Leave interval rewrite for another PR
mscuthbert Aug 17, 2022
fee7d88
Merge branch 'master' into remove-star-args
mscuthbert Aug 17, 2022
76de5fa
mypy, flake, lint
mscuthbert Aug 17, 2022
e8928cf
two more lints
mscuthbert Aug 17, 2022
90f481f
more mypy
mscuthbert Aug 18, 2022
31ac8f2
findConsecutiveNotes overload typing
mscuthbert Aug 18, 2022
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
Prev Previous commit
Next Next commit
discrete analysis
mscuthbert committed Aug 15, 2022

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
commit 81f3d5a3803e60ff1659a54c0a19b668b9ab8af3
18 changes: 7 additions & 11 deletions music21/analysis/discrete.py
Original file line number Diff line number Diff line change
@@ -1284,7 +1284,11 @@ def getSolution(self, sStream):
# -----------------------------------------------------------------------------
# public access function

def analyzeStream(streamObj, *args, **keywords):
def analyzeStream(
streamObj: 'music21.stream.Stream',
method: str,
*args,
**keywords):
'''
Public interface to discrete analysis methods to be applied
to a Stream given as an argument. Methods return process-specific data format.
@@ -1316,21 +1320,13 @@ def analyzeStream(streamObj, *args, **keywords):
<music21.key.Key of f# minor>
>>> s.analyze('span')
<music21.interval.Interval m21>

'''
method = None
if 'method' in keywords:
method = keywords['method']

if args:
method = args[0]

if method == 'range':
# getPitchRanges() was removed in v7
# this synonym is being added for compatibility
method = 'span'

match = analysisClassFromMethodName(method)
match: t.Optional[t.Callable] = analysisClassFromMethodName(method)

if match is not None:
obj = match() # NOTE: Cuthbert, this was previously analysisClassName()? - out of scope
@@ -1342,7 +1338,7 @@ def analyzeStream(streamObj, *args, **keywords):


# noinspection SpellCheckingInspection
def analysisClassFromMethodName(method):
def analysisClassFromMethodName(method: str):
'''
Returns an analysis class given a method name, or None if none can be found

32 changes: 14 additions & 18 deletions music21/analysis/reduction.py
Original file line number Diff line number Diff line change
@@ -461,7 +461,15 @@ class PartReduction:
If the `normalize` parameter is False, no normalization will take place. The default is True.

'''
def __init__(self, srcScore=None, *args, **keywords):
def __init__(self,
srcScore=None,
*args,
partGroups: t.Optional[t.Dict[str, t.Any]] = None,
fillByMeasure: bool = True,
segmentByTarget: bool = True,
normalize: bool = True,
normalizeByPart: bool = False,
**keywords):
if srcScore is None:
return
if not isinstance(srcScore, stream.Score):
@@ -475,26 +483,14 @@ def __init__(self, srcScore=None, *args, **keywords):

# define how parts are grouped
# a list of dictionaries, with keys for name, color, and a match list
self._partGroups = None
if 'partGroups' in keywords:
self._partGroups = keywords['partGroups']
self._partGroups = partGroups

self._fillByMeasure = True
if 'fillByMeasure' in keywords:
self._fillByMeasure = keywords['fillByMeasure']
self._fillByMeasure = fillByMeasure

# We re-partition if the spans change
self._segmentByTarget = True
if 'segmentByTarget' in keywords:
self._segmentByTarget = keywords['segmentByTarget']

self._normalizeByPart = False # norm by all parts is default
if 'normalizeByPart' in keywords:
self._normalizeByPart = keywords['normalizeByPart']

self._normalizeToggle = True
if 'normalize' in keywords:
self._normalizeToggle = keywords['normalize']
self._segmentByTarget = segmentByTarget
self._normalizeByPart = normalizeByPart # norm by all parts is default
self._normalizeToggle = normalize

# check that there are measures
for p in self._score.parts:
35 changes: 10 additions & 25 deletions music21/converter/__init__.py
Original file line number Diff line number Diff line change
@@ -1191,6 +1191,9 @@ def parseURL(url,

def parse(value: t.Union[bundles.MetadataEntry, bytes, str, pathlib.Path],
*args,
forceSource: bool = False,
number: t.Optional[int] = None,
format: t.Optional[str] = None, # pylint: disable=redefined-builtin
**keywords) -> t.Union[stream.Score, stream.Part, stream.Opus]:
r'''
Given a file path, encoded data in a Python string, or a URL, attempt to
@@ -1241,25 +1244,7 @@ def parse(value: t.Union[bundles.MetadataEntry, bytes, str, pathlib.Path],
possibility and has been removed.
'''
# environLocal.printDebug(['attempting to parse()', value])
if 'forceSource' in keywords:
forceSource = keywords['forceSource']
del keywords['forceSource']
else:
forceSource = False

# see if a work number is defined; for multi-work collections
if 'number' in keywords:
number = keywords['number']
del keywords['number']
else:
number = None

if 'format' in keywords:
m21Format = keywords['format']
del keywords['format']
else:
m21Format = None

valueStr: str
if isinstance(value, bytes):
valueStr = value.decode('utf-8', 'ignore')
@@ -1281,7 +1266,7 @@ def parse(value: t.Union[bundles.MetadataEntry, bytes, str, pathlib.Path],
and value[1] is None
and _osCanLoad(str(value[0]))):
# comes from corpus.search
return parseFile(value[0], format=m21Format, **keywords)
return parseFile(value[0], format=format, **keywords)
elif (common.isListLike(value)
and isinstance(value, collections.abc.Sequence)
and len(value) == 2
@@ -1297,26 +1282,26 @@ def parse(value: t.Union[bundles.MetadataEntry, bytes, str, pathlib.Path],
'If using a two-element list, the second value must be an integer number, '
f'not {value[1]!r}'
)
sc = parseFile(value[0], format=m21Format, **keywords)
sc = parseFile(value[0], format=format, **keywords)
if isinstance(sc, stream.Opus):
return sc.getScoreByNumber(value[1])
else:
return sc
# a midi string, must come before os.path.exists test
elif not isinstance(value, bytes) and valueStr.startswith('MThd'):
return parseData(value, number=number, format=m21Format, **keywords)
return parseData(value, number=number, format=format, **keywords)
elif (not isinstance(value, bytes)
and _osCanLoad(valueStr)):
return parseFile(valueStr, number=number, format=m21Format,
return parseFile(valueStr, number=number, format=format,
forceSource=forceSource, **keywords)
elif (not isinstance(value, bytes)
and _osCanLoad(common.cleanpath(valueStr))):
return parseFile(common.cleanpath(valueStr), number=number, format=m21Format,
return parseFile(common.cleanpath(valueStr), number=number, format=format,
forceSource=forceSource, **keywords)
elif not isinstance(valueStr, bytes) and (valueStr.startswith('http://')
or valueStr.startswith('https://')):
# it's a url; may need to broaden these criteria
return parseURL(value, number=number, format=m21Format,
return parseURL(value, number=number, format=format,
forceSource=forceSource, **keywords)
elif isinstance(value, pathlib.Path):
raise FileNotFoundError(f'Cannot find file in {str(value)}')
@@ -1325,7 +1310,7 @@ def parse(value: t.Union[bundles.MetadataEntry, bytes, str, pathlib.Path],
raise FileNotFoundError(f'Cannot find file in {str(value)}')
else:
# all else, including MidiBytes
return parseData(value, number=number, format=m21Format, **keywords)
return parseData(value, number=number, format=format, **keywords)


def freeze(streamObj, fmt=None, fp=None, fastButUnsafe=False, zipType='zlib') -> pathlib.Path:
26 changes: 17 additions & 9 deletions music21/converter/subConverters.py
Original file line number Diff line number Diff line change
@@ -468,11 +468,17 @@ class ConverterLilypond(SubConverter):
'svg': ''} # sic! (Why?)
codecWrite = True

def write(self, obj, fmt, fp=None, subformats=None, **keywords): # pragma: no cover
def write(self,
obj,
fmt,
fp=None,
subformats=None,
*,
coloredVariants: bool = False,
**keywords): # pragma: no cover
from music21 import lily
conv = lily.translate.LilypondConverter()
if 'coloredVariants' in keywords and keywords['coloredVariants'] is True:
conv.coloredVariants = True
conv.coloredVariants = coloredVariants

if subformats is not None and 'pdf' in subformats:
conv.loadFromMusic21Object(obj)
@@ -543,14 +549,16 @@ class ConverterVexflow(SubConverter):
registerFormats = ('vexflow',)
registerOutputExtensions = ('html',)

def write(self, obj, fmt, fp=None, subformats=None, **keywords): # pragma: no cover
def write(self,
obj,
fmt,
fp=None,
subformats=None,
*,
local: bool = False
**keywords): # pragma: no cover
# from music21 import vexflow
from music21.vexflow import toMusic21j as vexflow
if 'local' in keywords:
local = keywords['local']
else:
local = False

dataStr = vexflow.fromObject(obj, mode='html', local=local)
fp = self.writeDataStream(fp, dataStr)
return fp
4 changes: 3 additions & 1 deletion music21/vexflow/toMusic21j.py
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
]


def fromObject(thisObject, mode='html', local=False):
def fromObject(thisObject, *, mode='html', local=False):
'''
returns a string of data for a given Music21Object such as a Score, Note, etc. that
can be displayed in a browser using the music21j package. Called by .show('vexflow').
@@ -68,6 +68,8 @@ def fromObject(thisObject, mode='html', local=False):
<body>
</body>
</html>

Changed in v.8 -- mode and useLocal are keyword only.
'''
conv = VexflowPickler()
conv.mode = mode