summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2021-05-02 12:53:02 -0700
committerGitHub <noreply@github.com>2021-05-02 12:53:02 -0700
commit61138ca629242a998b495ce05b5cd25df2429900 (patch)
tree8413811bb82ca17496f4c842485278807f979edf
parentc4460cb9dffbd9b7ee000dc31388d5f45fe484a0 (diff)
parent91fc81764a347797b79dfe6fa901a77b63d87473 (diff)
downloadpep8-61138ca629242a998b495ce05b5cd25df2429900.tar.gz
Merge pull request #989 from cdce8p/whitespace-match-false-positive
Fix false-positive E211 with match and case
-rw-r--r--.github/workflows/main.yml3
-rwxr-xr-xpycodestyle.py13
-rw-r--r--testsuite/python310.py9
-rw-r--r--testsuite/support.py2
4 files changed, 23 insertions, 4 deletions
diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml
index 4624d21..59dfac3 100644
--- a/.github/workflows/main.yml
+++ b/.github/workflows/main.yml
@@ -41,6 +41,9 @@ jobs:
py: 3.9
toxenv: py
- os: ubuntu-latest
+ py: 3.10-dev
+ toxenv: py
+ - os: ubuntu-latest
py: 3.9
toxenv: flake8
runs-on: ${{ matrix.os }}
diff --git a/pycodestyle.py b/pycodestyle.py
index c091639..1ceff9e 100755
--- a/pycodestyle.py
+++ b/pycodestyle.py
@@ -811,14 +811,21 @@ 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
+ (
+ sys.version_info <= (3, 10) or
+ not keyword.issoftkeyword(prev_text)
+ )
+ ):
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..83b7bb4
--- /dev/null
+++ b/testsuite/python310.py
@@ -0,0 +1,9 @@
+#: Okay
+var, var2 = 1, 2
+match (var, var2):
+ case [2, 3]:
+ pass
+ case (1, 2):
+ pass
+ case _:
+ print("Default")
diff --git a/testsuite/support.py b/testsuite/support.py
index 8241a92..eb8b443 100644
--- a/testsuite/support.py
+++ b/testsuite/support.py
@@ -169,7 +169,7 @@ def init_tests(pep8style):
def run_tests(filename):
"""Run all the tests from a file."""
# Skip tests meant for higher versions of python
- ver_match = re.search(r'python(\d)(\d)?\.py$', filename)
+ ver_match = re.search(r'python(\d)(\d+)?\.py$', filename)
if ver_match:
test_against_version = tuple(int(val or 0)
for val in ver_match.groups())