Skip to content

Commit 61138ca

Browse files
authored
Merge pull request #989 from cdce8p/whitespace-match-false-positive
Fix false-positive E211 with match and case
2 parents c4460cb + 91fc817 commit 61138ca

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

.github/workflows/main.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ jobs:
4040
- os: ubuntu-latest
4141
py: 3.9
4242
toxenv: py
43+
- os: ubuntu-latest
44+
py: 3.10-dev
45+
toxenv: py
4346
- os: ubuntu-latest
4447
py: 3.9
4548
toxenv: flake8

pycodestyle.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -811,14 +811,21 @@ def whitespace_before_parameters(logical_line, tokens):
811811
prev_type, prev_text, __, prev_end, __ = tokens[0]
812812
for index in range(1, len(tokens)):
813813
token_type, text, start, end, __ = tokens[index]
814-
if (token_type == tokenize.OP and
814+
if (
815+
token_type == tokenize.OP and
815816
text in '([' and
816817
start != prev_end and
817818
(prev_type == tokenize.NAME or prev_text in '}])') and
818819
# Syntax "class A (B):" is allowed, but avoid it
819820
(index < 2 or tokens[index - 2][1] != 'class') and
820-
# Allow "return (a.foo for a in range(5))"
821-
not keyword.iskeyword(prev_text)):
821+
# Allow "return (a.foo for a in range(5))"
822+
not keyword.iskeyword(prev_text) and
823+
# 'match' and 'case' are only soft keywords
824+
(
825+
sys.version_info <= (3, 10) or
826+
not keyword.issoftkeyword(prev_text)
827+
)
828+
):
822829
yield prev_end, "E211 whitespace before '%s'" % text
823830
prev_type = token_type
824831
prev_text = text

testsuite/python310.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#: Okay
2+
var, var2 = 1, 2
3+
match (var, var2):
4+
case [2, 3]:
5+
pass
6+
case (1, 2):
7+
pass
8+
case _:
9+
print("Default")

testsuite/support.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def init_tests(pep8style):
169169
def run_tests(filename):
170170
"""Run all the tests from a file."""
171171
# Skip tests meant for higher versions of python
172-
ver_match = re.search(r'python(\d)(\d)?\.py$', filename)
172+
ver_match = re.search(r'python(\d)(\d+)?\.py$', filename)
173173
if ver_match:
174174
test_against_version = tuple(int(val or 0)
175175
for val in ver_match.groups())

0 commit comments

Comments
 (0)