diff options
author | Anthony Sottile <asottile@umich.edu> | 2021-05-02 12:53:02 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-02 12:53:02 -0700 |
commit | 61138ca629242a998b495ce05b5cd25df2429900 (patch) | |
tree | 8413811bb82ca17496f4c842485278807f979edf /pycodestyle.py | |
parent | c4460cb9dffbd9b7ee000dc31388d5f45fe484a0 (diff) | |
parent | 91fc81764a347797b79dfe6fa901a77b63d87473 (diff) | |
download | pep8-61138ca629242a998b495ce05b5cd25df2429900.tar.gz |
Merge pull request #989 from cdce8p/whitespace-match-false-positive
Fix false-positive E211 with match and case
Diffstat (limited to 'pycodestyle.py')
-rwxr-xr-x | pycodestyle.py | 13 |
1 files changed, 10 insertions, 3 deletions
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 |