All patches and comments are welcome. Please squash your changes to logical
commits before using git-format-patch and git-send-email to
patches@git.madduck.net.
If you'd read over the Git project's submission guidelines and adhered to them,
I'd be especially grateful.
summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
5e2bb52)
Fixes #2648.
Co-authored-by: Batuhan Taskaya <isidentical@gmail.com>
times, like `match re.match()` (#2661)
- Fix assignment to environment variables in Jupyter Notebooks (#2642)
- Add `flake8-simplify` and `flake8-comprehensions` plugins (#2653)
times, like `match re.match()` (#2661)
- Fix assignment to environment variables in Jupyter Notebooks (#2642)
- Add `flake8-simplify` and `flake8-comprehensions` plugins (#2653)
+- Fix parser error location on invalid syntax in a `match` statement (#2649)
# Python 3.10+
grammars.append(pygram.python_grammar_soft_keywords)
# If we have to parse both, try to parse async as a keyword first
# Python 3.10+
grammars.append(pygram.python_grammar_soft_keywords)
# If we have to parse both, try to parse async as a keyword first
- if not supports_feature(target_versions, Feature.ASYNC_IDENTIFIERS):
- # Python 3.7+
+ if not supports_feature(
+ target_versions, Feature.ASYNC_IDENTIFIERS
+ ) and not supports_feature(target_versions, Feature.PATTERN_MATCHING):
+ # Python 3.7-3.9
grammars.append(
pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords
)
grammars.append(
pygram.python_grammar_no_print_statement_no_exec_statement_async_keywords
)
--- /dev/null
+# First match, no errors
+match something:
+ case bla():
+ pass
+
+# Problem on line 10
+match invalid_case:
+ case valid_case:
+ pass
+ case a := b:
+ pass
+ case valid_case:
+ pass
+
+# No problems either
+match something:
+ case bla():
+ pass
assert_format(source, expected, mode, minimum_version=(3, 10))
assert_format(source, expected, mode, minimum_version=(3, 10))
+def test_patma_invalid() -> None:
+ source, expected = read_data("pattern_matching_invalid")
+ mode = black.Mode(target_versions={black.TargetVersion.PY310})
+ with pytest.raises(black.parsing.InvalidInput) as exc_info:
+ assert_format(source, expected, mode, minimum_version=(3, 10))
+
+ exc_info.match("Cannot parse: 10:11")
+
+
def test_docstring_no_string_normalization() -> None:
"""Like test_docstring but with string normalization off."""
source, expected = read_data("docstring_no_string_normalization")
def test_docstring_no_string_normalization() -> None:
"""Like test_docstring but with string normalization off."""
source, expected = read_data("docstring_no_string_normalization")