diff options
author | Anthony Sottile <asottile@umich.edu> | 2021-05-02 17:22:06 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-02 17:22:06 -0700 |
commit | 0f079a061590217515421fc337df8dbf3563fed5 (patch) | |
tree | 98dabf41832f52887e62b12f62d088a35fba0909 | |
parent | 3d0ac73d8045b5fa771dbbf594ca0b9a4e581e15 (diff) | |
parent | 3527106c822f52b01ce516e6ccf4cb30b69e3a87 (diff) | |
download | pep8-0f079a061590217515421fc337df8dbf3563fed5.tar.gz |
Merge pull request #990 from cdce8p/whitespace-match-case
Add whitespace checks for ``match`` and ``case``
-rwxr-xr-x | pycodestyle.py | 11 | ||||
-rw-r--r-- | testsuite/python310.py | 18 | ||||
-rw-r--r-- | tox.ini | 2 |
3 files changed, 30 insertions, 1 deletions
diff --git a/pycodestyle.py b/pycodestyle.py index 0f2f078..7f00739 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -163,6 +163,7 @@ STARTSWITH_INDENT_STATEMENT_REGEX = re.compile( ))) ) DUNDER_REGEX = re.compile(r'^__([^\s]+)__ = ') +MATCH_CASE_REGEX = re.compile(r'^\s*\b(?:match|case)(\s*)(?=.*\:)') _checks = {'physical_line': {}, 'logical_line': {}, 'tree': {}} @@ -493,6 +494,16 @@ def whitespace_around_keywords(logical_line): elif len(after) > 1: yield match.start(2), "E271 multiple spaces after keyword" + if sys.version_info >= (3, 10): + match = MATCH_CASE_REGEX.match(logical_line) + if match: + if match[1] == ' ': + return + if match[1] == '': + yield match.start(1), "E275 missing whitespace after keyword" + else: + yield match.start(1), "E271 multiple spaces after keyword" + @register_check def missing_whitespace_after_import_keyword(logical_line): diff --git a/testsuite/python310.py b/testsuite/python310.py index 83b7bb4..e78d372 100644 --- a/testsuite/python310.py +++ b/testsuite/python310.py @@ -7,3 +7,21 @@ match (var, var2): pass case _: print("Default") +#: E271:2:6 E271:3:9 E271:5:9 E271:7:9 +var = 1 +match var: + case 1: + pass + case 2: + pass + case ( + 3 + ): + pass +#: E275:2:6 E275:3:9 E275:5:9 +var = 1 +match(var): + case(1): + pass + case_: + pass @@ -4,7 +4,7 @@ # and then run "tox" from this directory. [tox] -envlist = py27, py34, py35, py36, py37, py38, pypy, pypy3, jython +envlist = py27, py34, py35, py36, py37, py38, py39, py310, pypy, pypy3, jython skip_missing_interpreters = True [testenv] |