-
Notifications
You must be signed in to change notification settings - Fork 406
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
+19
−6
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,6 @@ | |
from __future__ import annotations | ||
|
||
from collections import deque | ||
import collections.abc | ||
import copy | ||
from http.client import responses | ||
import io | ||
|
@@ -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, | ||
|
@@ -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. | ||
|
||
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Was preventing the more informative error message below, allowing later |
||
and _osCanLoad(str(value[0]))): | ||
# corpus or other file with movement number | ||
if not isinstance(value[0], str): | ||
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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