summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2021-05-02 18:41:16 +0200
committerMarc Mueller <30130371+cdce8p@users.noreply.github.com>2021-05-02 18:42:29 +0200
commite2ebb356246615e1749a5366592e4523bb8752ec (patch)
tree9237708703ca1649397da38b48e2d21c13e729e7
parentc4460cb9dffbd9b7ee000dc31388d5f45fe484a0 (diff)
downloadpep8-e2ebb356246615e1749a5366592e4523bb8752ec.tar.gz
Fix false-positive E211 with match and case
-rwxr-xr-xpycodestyle.py10
-rw-r--r--testsuite/python310.py12
2 files changed, 19 insertions, 3 deletions
diff --git a/pycodestyle.py b/pycodestyle.py
index c091639..8124f9d 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -811,14 +811,18 @@ def whitespace_before_parameters(logical_line, tokens):
prev_type, prev_text, __, prev_end, __ = tokens[0]
for index in range(1, len(tokens)):
token_type, text, start, end, __ = tokens[index]
- if (token_type == tokenize.OP and
+ if (
+ token_type == tokenize.OP and
text in '([' and
start != prev_end and
(prev_type == tokenize.NAME or prev_text in '}])') and
# Syntax "class A (B):" is allowed, but avoid it
(index < 2 or tokens[index - 2][1] != 'class') and
- # Allow "return (a.foo for a in range(5))"
- not keyword.iskeyword(prev_text)):
+ # Allow "return (a.foo for a in range(5))"
+ not keyword.iskeyword(prev_text) and
+ # 'match' and 'case' are only soft keywords
+ prev_text not in ('match', 'case')
+ ):
yield prev_end, "E211 whitespace before '%s'" % text
prev_type = token_type
prev_text = text
diff --git a/testsuite/python310.py b/testsuite/python310.py
new file mode 100644
index 0000000..b72bf6d
--- /dev/null
+++ b/testsuite/python310.py
@@ -0,0 +1,12 @@
+var, var2 = 1, 2
+#: Okay
+match (var, var2):
+ #: Okay
+ case [2, 3]:
+ pass
+ #: Okay
+ case (1, 2):
+ pass
+ #: Okay
+ case _:
+ print("Default")