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

Fix argument annotation in converter.parse() signature #1665

Merged
merged 1 commit into from
Jan 2, 2024
Merged
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
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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant now that isListLike no longer permits sets

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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was preventing the more informative error message below, allowing later elif blocks to match and crash.

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))
Comment on lines +2079 to +2080
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow... bug.


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
Loading