Skip to content

Commit

Permalink
Merge pull request #1665 from cuthbertLab/fix-mypy-error
Browse files Browse the repository at this point in the history
Fix argument annotation in `converter.parse()` signature
  • Loading branch information
mscuthbert authored Jan 2, 2024
2 parents 7c719f8 + 515e0e6 commit defd61e
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions music21/converter/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
from __future__ import annotations

from collections import deque
import collections.abc
import copy
from http.client import responses
import io
Expand Down Expand Up @@ -1303,7 +1302,7 @@ def parseURL(url,
return v.stream


def parse(value: bundles.MetadataEntry | bytes | str | pathlib.Path,
def parse(value: bundles.MetadataEntry | bytes | str | pathlib.Path | list | tuple,
*,
forceSource: bool = False,
number: int | None = None,
Expand All @@ -1316,7 +1315,9 @@ def parse(value: bundles.MetadataEntry | bytes | str | pathlib.Path,
preference to "allow".
Keywords can include `number` which specifies a piece number in a file of
multi-piece file.
multi-piece file. (Otherwise, a particular score from an
:class:`~music21.stream.Opus` can also be extracted by providing a
two-element list or tuple of the form (path, number) to the `value` argument.)
`format` specifies the format to parse the line of text or the file as.
Expand Down Expand Up @@ -1375,16 +1376,13 @@ def parse(value: bundles.MetadataEntry | bytes | str | pathlib.Path,
valueStr = ''

if (common.isListLike(value)
and isinstance(value, collections.abc.Sequence)
and len(value) == 2
and value[1] is None
and _osCanLoad(str(value[0]))):
# comes from corpus.search
return parseFile(value[0], format=format, **keywords)
elif (common.isListLike(value)
and isinstance(value, collections.abc.Sequence)
and len(value) == 2
and isinstance(value[1], int)
and _osCanLoad(str(value[0]))):
# corpus or other file with movement number
if not isinstance(value[0], str):
Expand Down Expand Up @@ -2072,6 +2070,21 @@ def testConversionABCWorkFromOpus(self):
'<music21.beam.Beams <music21.beam.Beam 1/start>/<music21.beam.Beam 2/start>>')
# s.show()

def testConversionABCWorkFromOpusWithoutKeyword(self):
fp = common.getSourceFilePath() / 'corpus' / 'essenFolksong' / 'testd.abc'

s = parse((str(fp), None))
self.assertIsInstance(s, stream.Opus)

with self.assertRaises(ConverterException):
parse((fp, 8))

with self.assertRaises(ConverterException):
parse((str(fp), (8,)))

s = parse((str(fp), 8))
self.assertIsInstance(s, stream.Score)

def testConversionMusedata(self):
fp = common.getSourceFilePath() / 'musedata' / 'testPrimitive' / 'test01'
s = parse(fp)
Expand Down

0 comments on commit defd61e

Please sign in to comment.