From 75ad6a95fdb920559a3112b35dc8391938216897 Mon Sep 17 00:00:00 2001 From: Allison Karlitskaya Date: Tue, 21 Nov 2023 11:28:02 +0100 Subject: [PATCH 01/12] testing: add a pair of E303 testcases Add two test cases to verify that pycodestyle correctly flags 2 empty lines in non-toplevel contexts, even outside of functions: one for two empty lines between class methods and one for two empty lines in the indented body of an `if:` statement at toplevel. --- testing/data/E30.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/testing/data/E30.py b/testing/data/E30.py index ebe4e9d2..7ef46890 100644 --- a/testing/data/E30.py +++ b/testing/data/E30.py @@ -75,6 +75,20 @@ def a(): #: +#: E303:6:5 +class xyz: + def a(self): + pass + + + def b(self): + pass +#: E303:5:5 +if True: + a = 1 + + + a = 2 #: E304:3:1 @decorator From 9dc066bc792ef2b58e87ef2fd5b5e0203c520c30 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Wed, 27 Dec 2023 00:07:24 -0500 Subject: [PATCH 02/12] improve backtracking of COMPARE_TYPE_REGEX --- pycodestyle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pycodestyle.py b/pycodestyle.py index 3354346a..2f092c40 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -126,8 +126,8 @@ COMPARE_NEGATIVE_REGEX = re.compile(r'\b(?%&^]+|:=)(\s*)') From 2a9ee347e09ec4f00bc9e085cf4c7110a257595b Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Jan 2024 21:35:32 +0000 Subject: [PATCH 03/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pycqa/flake8: 6.1.0 → 7.0.0](https://github.com/pycqa/flake8/compare/6.1.0...7.0.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 8b1ea6d2..abecae48 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,6 +22,6 @@ repos: hooks: - id: setup-cfg-fmt - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + rev: 7.0.0 hooks: - id: flake8 From 2a612c15c24afaf09fe585fcb5038a3cac54c3f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Raphael=20D=C3=BCmig?= Date: Tue, 6 Feb 2024 22:24:25 +0200 Subject: [PATCH 04/12] prevent false positive for E721 on member function E721 was reported on the result of member functions of name "type" with one parameter, if those occurred on the left side of the comparison. --- pycodestyle.py | 2 +- testing/data/E72.py | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pycodestyle.py b/pycodestyle.py index 2f092c40..9adbb6b1 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -127,7 +127,7 @@ r'(in|is)\s') COMPARE_TYPE_REGEX = re.compile( r'[=!]=\s+type(?:\s*\(\s*([^)]*[^\s)])\s*\))' - r'|\btype(?:\s*\(\s*([^)]*[^\s)])\s*\))\s+[=!]=' + r'|(?%&^]+|:=)(\s*)') diff --git a/testing/data/E72.py b/testing/data/E72.py index ac55a958..5d1046cb 100644 --- a/testing/data/E72.py +++ b/testing/data/E72.py @@ -5,6 +5,8 @@ if type(res) != type(""): pass #: Okay +res.type("") == "" +#: Okay import types if res == types.IntType: From 45e2d9f9726d9682f9baadc11c61cc6c7af56c72 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 20 Feb 2024 01:17:01 +0000 Subject: [PATCH 05/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.15.0 → v3.15.1](https://github.com/asottile/pyupgrade/compare/v3.15.0...v3.15.1) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index abecae48..5aecb4eb 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: - id: reorder-python-imports args: [--py38-plus] - repo: https://github.com/asottile/pyupgrade - rev: v3.15.0 + rev: v3.15.1 hooks: - id: pyupgrade args: [--py38-plus] From 72668f67e94d58e69914dd4b139907956ef79575 Mon Sep 17 00:00:00 2001 From: augustelalande Date: Fri, 8 Mar 2024 15:42:38 -0500 Subject: [PATCH 06/12] fix E502 being disabled after a comment --- pycodestyle.py | 2 ++ testing/data/E50.py | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/pycodestyle.py b/pycodestyle.py index 9adbb6b1..6443a42a 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -1269,6 +1269,8 @@ def explicit_line_join(logical_line, tokens): comment = True if start[0] != prev_start and parens and backslash and not comment: yield backslash, "E502 the backslash is redundant between brackets" + if start[0] != prev_start: + comment = False # Reset comment flag on newline if end[0] != prev_end: if line.rstrip('\r\n').endswith('\\'): backslash = (end[0], len(line.splitlines()[-1]) - 1) diff --git a/testing/data/E50.py b/testing/data/E50.py index 6ab50c88..4870fcc2 100644 --- a/testing/data/E50.py +++ b/testing/data/E50.py @@ -25,6 +25,13 @@ if (foo is None and bar is "e000" and \ blah == 'yeah'): blah = 'yeahnah' +#: E502 W503 W503 +y = ( + 2 + 2 # \ + + 3 # \ + + 4 \ + + 3 +) # #: Okay a = ('AAA' From 6febb0d05ff37a177ddf10190804b0e0076d84d8 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 25 Mar 2024 22:47:40 +0000 Subject: [PATCH 07/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.15.1 → v3.15.2](https://github.com/asottile/pyupgrade/compare/v3.15.1...v3.15.2) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5aecb4eb..0b95e30d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: - id: reorder-python-imports args: [--py38-plus] - repo: https://github.com/asottile/pyupgrade - rev: v3.15.1 + rev: v3.15.2 hooks: - id: pyupgrade args: [--py38-plus] From 04f579dd76aa0294db65c3dbbbd110c80609137e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 8 Apr 2024 23:37:50 +0000 Subject: [PATCH 08/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pre-commit/pre-commit-hooks: v4.5.0 → v4.6.0](https://github.com/pre-commit/pre-commit-hooks/compare/v4.5.0...v4.6.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0b95e30d..541017f9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,7 +1,7 @@ exclude: ^testing/data/ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 + rev: v4.6.0 hooks: - id: check-yaml - id: debug-statements From 53591a50faf21c27d9ffaeda75dd869fbec19a20 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 3 Jun 2024 23:13:12 +0000 Subject: [PATCH 09/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/reorder-python-imports: v3.12.0 → v3.13.0](https://github.com/asottile/reorder-python-imports/compare/v3.12.0...v3.13.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 541017f9..f1eec7fd 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/asottile/reorder-python-imports - rev: v3.12.0 + rev: v3.13.0 hooks: - id: reorder-python-imports args: [--py38-plus] From 5be6ca17fcd04b5e8d7bf4d8c57daf9cd17b0bea Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 10 Jun 2024 23:29:23 +0000 Subject: [PATCH 10/12] [pre-commit.ci] pre-commit autoupdate MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/asottile/pyupgrade: v3.15.2 → v3.16.0](https://github.com/asottile/pyupgrade/compare/v3.15.2...v3.16.0) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f1eec7fd..9abea703 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -13,7 +13,7 @@ repos: - id: reorder-python-imports args: [--py38-plus] - repo: https://github.com/asottile/pyupgrade - rev: v3.15.2 + rev: v3.16.0 hooks: - id: pyupgrade args: [--py38-plus] From 3cedd4c74b5f467fc4c1cde5a8ac2503a54b60db Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 15 Jun 2024 14:29:53 -0400 Subject: [PATCH 11/12] add new error E204 for whitespace after decorator @ --- docs/intro.rst | 2 ++ pycodestyle.py | 7 +++++++ testing/data/E20.py | 17 +++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/docs/intro.rst b/docs/intro.rst index 8c74c782..a7187a27 100644 --- a/docs/intro.rst +++ b/docs/intro.rst @@ -262,6 +262,8 @@ This is the current list of error and warning codes: +------------+----------------------------------------------------------------------+ | E203 | whitespace before ',', ';', or ':' | +------------+----------------------------------------------------------------------+ +| E204 | whitespace after decorator '@' | ++------------+----------------------------------------------------------------------+ +------------+----------------------------------------------------------------------+ | E211 | whitespace before '(' | +------------+----------------------------------------------------------------------+ diff --git a/pycodestyle.py b/pycodestyle.py index 6443a42a..139ae2ba 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -120,6 +120,7 @@ ERRORCODE_REGEX = re.compile(r'\b[A-Z]\d{3}\b') DOCSTRING_REGEX = re.compile(r'u?r?["\']') EXTRANEOUS_WHITESPACE_REGEX = re.compile(r'[\[({][ \t]|[ \t][\]}),;:](?!=)') +WHITESPACE_AFTER_DECORATOR_REGEX = re.compile(r'@\s') WHITESPACE_AFTER_COMMA_REGEX = re.compile(r'[,;:]\s*(?: |\t)') COMPARE_SINGLETON_REGEX = re.compile(r'(\bNone|\bFalse|\bTrue)?\s*([=!]=)' r'\s*(?(1)|(None|False|True))\b') @@ -438,6 +439,9 @@ def extraneous_whitespace(logical_line): E203: if x == 4: print x, y; x, y = y , x E203: if x == 4: print x, y ; x, y = y, x E203: if x == 4 : print x, y; x, y = y, x + + Okay: @decorator + E204: @ decorator """ line = logical_line for match in EXTRANEOUS_WHITESPACE_REGEX.finditer(line): @@ -451,6 +455,9 @@ def extraneous_whitespace(logical_line): code = ('E202' if char in '}])' else 'E203') # if char in ',;:' yield found, f"{code} whitespace before '{char}'" + if WHITESPACE_AFTER_DECORATOR_REGEX.match(logical_line): + yield 1, "E204 whitespace after decorator '@'" + @register_check def whitespace_around_keywords(logical_line): diff --git a/testing/data/E20.py b/testing/data/E20.py index 20c6dfd8..ed21b213 100644 --- a/testing/data/E20.py +++ b/testing/data/E20.py @@ -75,4 +75,21 @@ x, y = y, x a[b1, :] == a[b1, ...] b = a[:, b1] +#: E204:1:2 +@ decorator +def f(): + pass +#: E204:1:2 +@ decorator +def f(): + pass +#: E204:1:2 +@ decorator +def f(): + pass +#: E204:2:6 +if True: + @ decorator + def f(): + pass #: From 6f60985ab563c3657da8d44ba391128b40c9ea24 Mon Sep 17 00:00:00 2001 From: Anthony Sottile Date: Sat, 15 Jun 2024 17:28:03 -0400 Subject: [PATCH 12/12] Release 2.12.0 --- CHANGES.txt | 9 +++++++++ pycodestyle.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/CHANGES.txt b/CHANGES.txt index 55c000aa..6e8f9f67 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,6 +1,15 @@ Changelog ========= +2.12.0 (2024-06-15) +------------------- + +Changes: + +* E721: Fix false positive of the form `x.type(...) ==`. PR #1228. +* E502: Fix false-negative with a backslash escape in a comment. PR #1234. +* E204: New lint forbidding whitespace after decorator `@`. PR #1247. + 2.11.1 (2023-10-12) ------------------- diff --git a/pycodestyle.py b/pycodestyle.py index 139ae2ba..19f88c2a 100755 --- a/pycodestyle.py +++ b/pycodestyle.py @@ -68,7 +68,7 @@ ): # pragma: no cover (