From 87fe5e58c2013b4b1949836c142993464b153237 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Tue, 2 May 2023 13:39:00 +0200 Subject: [doc] Apply black on the documentation where it makes sense (#8650) Co-authored-by: Daniel van Noord <13665637+DanielNoord@users.noreply.github.com> --- .pre-commit-config.yaml | 21 +++++++++++++++++++++ doc/data/messages/a/arguments-renamed/bad.py | 3 +++ doc/data/messages/a/arguments-renamed/good.py | 3 +++ doc/data/messages/a/assigning-non-slot/bad.py | 2 +- doc/data/messages/a/assigning-non-slot/good.py | 2 +- doc/data/messages/b/bad-chained-comparison/bad.py | 4 +++- doc/data/messages/b/bad-chained-comparison/good.py | 4 +++- doc/data/messages/b/bad-classmethod-argument/bad.py | 1 - .../messages/b/bad-classmethod-argument/good.py | 1 - doc/data/messages/b/bad-docstring-quotes/bad.py | 2 +- doc/data/messages/b/bad-format-string/bad.py | 2 +- doc/data/messages/b/bad-format-string/good.py | 2 +- doc/data/messages/b/bad-indentation/good.py | 2 +- doc/data/messages/b/bad-thread-instantiation/bad.py | 2 +- .../messages/b/bad-thread-instantiation/good.py | 2 +- doc/data/messages/c/cell-var-from-loop/bad.py | 2 ++ .../c/class-variable-slots-conflict/good.py | 2 +- doc/data/messages/c/compare-to-zero/bad.py | 4 ++-- doc/data/messages/c/comparison-with-callable/bad.py | 1 + .../messages/c/comparison-with-callable/good.py | 1 + doc/data/messages/c/confusing-with-statement/bad.py | 2 +- .../messages/c/confusing-with-statement/good.py | 4 ++-- .../messages/c/consider-merging-isinstance/bad.py | 3 ++- .../messages/c/consider-using-any-or-all/good.py | 2 +- doc/data/messages/c/consider-using-enumerate/bad.py | 2 +- .../messages/c/consider-using-enumerate/good.py | 2 +- doc/data/messages/c/consider-using-f-string/good.py | 2 +- doc/data/messages/c/consider-using-in/bad.py | 3 ++- doc/data/messages/c/consider-using-join/bad.py | 1 + doc/data/messages/d/deprecated-method/bad.py | 2 +- doc/data/messages/d/dict-init-mutate/bad.py | 4 ++-- doc/data/messages/d/dict-iter-missing-items/bad.py | 2 +- doc/data/messages/d/dict-iter-missing-items/good.py | 2 +- doc/data/messages/d/duplicate-code/bad/orange.py | 2 +- doc/data/messages/d/duplicate-value/bad.py | 2 +- doc/data/messages/d/duplicate-value/good.py | 2 +- doc/data/messages/e/exec-used/good.py | 9 +++++---- .../messages/f/forgotten-debug-statement/bad.py | 9 +++++++-- .../messages/f/forgotten-debug-statement/good.py | 7 ++++++- .../messages/f/format-combined-specification/bad.py | 2 +- .../f/format-combined-specification/good.py | 4 ++-- doc/data/messages/i/import-outside-toplevel/bad.py | 1 + doc/data/messages/i/import-private-name/bad.py | 3 ++- doc/data/messages/i/import-private-name/good.py | 2 +- doc/data/messages/i/init-is-generator/bad.py | 1 + doc/data/messages/i/init-is-generator/good.py | 1 + doc/data/messages/i/invalid-all-format/bad.py | 2 +- doc/data/messages/i/invalid-all-object/bad.py | 2 ++ doc/data/messages/i/invalid-all-object/good.py | 4 +++- .../messages/i/invalid-character-backspace/bad.py | 2 +- doc/data/messages/i/invalid-character-esc/bad.py | 2 +- doc/data/messages/i/invalid-character-sub/bad.py | 2 +- .../i/invalid-character-zero-width-space/bad.py | 2 +- doc/data/messages/i/invalid-envvar-default/bad.py | 2 +- doc/data/messages/i/invalid-envvar-default/good.py | 2 +- doc/data/messages/i/invalid-envvar-value/good.py | 2 +- doc/data/messages/i/invalid-format-index/good.py | 2 +- doc/data/messages/i/invalid-length-returned/bad.py | 2 +- doc/data/messages/i/invalid-metaclass/good.py | 1 + doc/data/messages/i/invalid-name/bad.py | 1 - doc/data/messages/i/invalid-name/good.py | 1 - .../messages/i/invalid-overridden-method/bad.py | 1 + .../messages/i/invalid-overridden-method/good.py | 1 + doc/data/messages/i/invalid-sequence-index/bad.py | 4 ++-- doc/data/messages/i/invalid-sequence-index/good.py | 2 +- doc/data/messages/i/invalid-slots-object/bad.py | 2 +- doc/data/messages/i/invalid-slots-object/good.py | 2 +- doc/data/messages/i/invalid-slots/good.py | 2 +- .../i/invalid-star-assignment-target/bad.py | 2 +- .../i/invalid-star-assignment-target/good.py | 2 +- .../messages/i/invalid-unary-operand-type/bad.py | 2 +- doc/data/messages/l/locally-disabled/bad.py | 1 + doc/data/messages/l/locally-disabled/good.py | 1 + .../messages/l/logging-format-interpolation/bad.py | 3 ++- .../messages/l/logging-format-interpolation/good.py | 2 +- .../messages/l/logging-fstring-interpolation/bad.py | 2 +- .../l/logging-fstring-interpolation/good.py | 2 +- doc/data/messages/l/logging-not-lazy/bad.py | 2 +- doc/data/messages/l/logging-not-lazy/good.py | 2 +- doc/data/messages/l/logging-too-few-args/bad.py | 2 +- doc/data/messages/l/logging-too-few-args/good.py | 2 +- doc/data/messages/l/logging-too-many-args/bad.py | 2 +- doc/data/messages/l/logging-too-many-args/good.py | 2 +- .../messages/l/logging-unsupported-format/bad.py | 2 +- doc/data/messages/m/magic-value-comparison/bad.py | 4 ++-- .../messages/m/misplaced-format-function/bad.py | 2 +- .../messages/m/misplaced-format-function/good.py | 2 +- doc/data/messages/m/missing-any-param-doc/bad.py | 2 +- doc/data/messages/m/missing-any-param-doc/good.py | 4 ++-- doc/data/messages/m/missing-class-docstring/bad.py | 1 - doc/data/messages/m/missing-final-newline/good.py | 2 +- doc/data/messages/m/missing-kwoa/bad.py | 3 ++- doc/data/messages/m/missing-kwoa/good.py | 1 + .../m/missing-parentheses-for-call-in-test/bad.py | 1 + .../m/missing-parentheses-for-call-in-test/good.py | 1 + doc/data/messages/m/missing-raises-doc/bad.py | 2 +- doc/data/messages/m/missing-raises-doc/good.py | 2 +- .../messages/n/named-expr-without-context/good.py | 4 ++-- doc/data/messages/n/no-else-continue/bad.py | 2 +- doc/data/messages/n/no-else-continue/good.py | 2 +- doc/data/messages/n/no-else-raise/bad.py | 4 ++-- doc/data/messages/n/no-else-raise/good.py | 2 +- doc/data/messages/n/no-self-use/bad.py | 1 - doc/data/messages/n/no-value-for-parameter/bad.py | 1 + doc/data/messages/n/no-value-for-parameter/good.py | 1 + doc/data/messages/o/overlapping-except/good.py | 6 +++++- .../p/positional-only-arguments-expected/bad.py | 3 ++- .../p/positional-only-arguments-expected/good.py | 1 + .../messages/r/redefined-argument-from-local/bad.py | 3 ++- .../r/redefined-argument-from-local/good.py | 2 +- doc/data/messages/r/return-in-init/bad.py | 1 - doc/data/messages/r/return-in-init/good.py | 1 - doc/data/messages/s/self-cls-assignment/bad.py | 2 +- doc/data/messages/s/self-cls-assignment/good.py | 2 +- .../messages/s/simplifiable-if-statement/bad.py | 3 ++- .../messages/s/subprocess-popen-preexec-fn/bad.py | 2 +- doc/data/messages/s/syntax-error/good.py | 6 +----- doc/data/messages/t/too-few-public-methods/good.py | 7 ++++++- .../messages/t/too-many-boolean-expressions/good.py | 2 +- doc/data/messages/t/too-many-locals/bad.py | 4 +++- .../messages/t/too-many-return-statements/bad.py | 14 +++++++------- .../messages/t/too-many-return-statements/good.py | 16 ++++++++-------- doc/data/messages/t/truncated-format-string/bad.py | 2 +- doc/data/messages/u/undefined-all-variable/bad.py | 1 + doc/data/messages/u/undefined-all-variable/good.py | 1 + .../u/unnecessary-direct-lambda-call/bad.py | 2 +- .../u/unnecessary-direct-lambda-call/good.py | 2 +- doc/data/messages/u/unnecessary-dunder-call/bad.py | 2 +- .../messages/u/unnecessary-lambda-assignment/bad.py | 2 +- .../u/unnecessary-lambda-assignment/good.py | 2 +- .../messages/u/unnecessary-list-index-lookup/bad.py | 2 +- .../u/unnecessary-list-index-lookup/good.py | 2 +- doc/data/messages/u/unnecessary-pass/bad.py | 1 + .../messages/u/unsupported-binary-operation/good.py | 2 +- .../messages/u/unsupported-membership-test/good.py | 1 + doc/data/messages/u/unused-format-string-key/bad.py | 7 +++++-- .../messages/u/unused-format-string-key/good.py | 5 ++++- doc/data/messages/u/unused-wildcard-import/bad.py | 3 ++- doc/data/messages/u/unused-wildcard-import/good.py | 3 ++- .../messages/u/useless-parent-delegation/bad.py | 2 -- .../messages/u/useless-parent-delegation/good.py | 1 - doc/data/messages/u/using-constant-test/bad.py | 4 ++-- doc/data/messages/u/using-constant-test/good.py | 2 +- doc/data/messages/w/while-used/bad.py | 4 ++-- doc/data/messages/w/while-used/good.py | 4 ++-- .../messages/w/wrong-exception-operation/bad.py | 4 ++-- .../messages/w/wrong-exception-operation/good.py | 2 +- doc/data/messages/w/wrong-import-position/bad.py | 4 ++-- doc/data/messages/w/wrong-import-position/good.py | 4 ++-- 149 files changed, 242 insertions(+), 161 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 48819fe3b..6b20db830 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -52,6 +52,27 @@ repos: - id: black args: [--safe, --quiet] exclude: *fixtures + - id: black + name: black-doc + args: [--safe, --quiet] + files: doc/data/messages/ + exclude: | + (?x)^( + doc/data/messages/b/bad-indentation/bad.py| + doc/data/messages/i/inconsistent-quotes/bad.py| + doc/data/messages/i/invalid-format-index/bad.py| + doc/data/messages/l/line-too-long/bad.py| + doc/data/messages/m/missing-final-newline/bad.py| + doc/data/messages/m/multiple-statements/bad.py| + doc/data/messages/r/redundant-u-string-prefix/bad.py| + doc/data/messages/s/superfluous-parens/bad.py| + doc/data/messages/s/syntax-error/bad.py| + doc/data/messages/t/too-many-ancestors/bad.py| + doc/data/messages/t/trailing-comma-tuple/bad.py| + doc/data/messages/t/trailing-newlines/bad.py| + doc/data/messages/t/trailing-whitespace/bad.py| + doc/data/messages/u/unnecessary-semicolon/bad.py + )$ - repo: https://github.com/Pierre-Sassoulas/black-disable-checker rev: v1.1.3 hooks: diff --git a/doc/data/messages/a/arguments-renamed/bad.py b/doc/data/messages/a/arguments-renamed/bad.py index 87b45a0d5..c9d785320 100644 --- a/doc/data/messages/a/arguments-renamed/bad.py +++ b/doc/data/messages/a/arguments-renamed/bad.py @@ -2,12 +2,15 @@ class Fruit: def brew(self, ingredient_name: str): print(f"Brewing a {type(self)} with {ingredient_name}") + class Apple(Fruit): ... + class Orange(Fruit): def brew(self, flavor: str): # [arguments-renamed] print(f"Brewing an orange with {flavor}") + for fruit, ingredient_name in [[Orange(), "thyme"], [Apple(), "cinnamon"]]: fruit.brew(ingredient_name=ingredient_name) diff --git a/doc/data/messages/a/arguments-renamed/good.py b/doc/data/messages/a/arguments-renamed/good.py index 0cd1db756..de6583806 100644 --- a/doc/data/messages/a/arguments-renamed/good.py +++ b/doc/data/messages/a/arguments-renamed/good.py @@ -2,12 +2,15 @@ class Fruit: def brew(self, ingredient_name: str): print(f"Brewing a {type(self)} with {ingredient_name}") + class Apple(Fruit): ... + class Orange(Fruit): def brew(self, ingredient_name: str): print(f"Brewing an orange with {ingredient_name}") + for fruit, ingredient_name in [[Orange(), "thyme"], [Apple(), "cinnamon"]]: fruit.brew(ingredient_name=ingredient_name) diff --git a/doc/data/messages/a/assigning-non-slot/bad.py b/doc/data/messages/a/assigning-non-slot/bad.py index a1a658ba2..506ad42cd 100644 --- a/doc/data/messages/a/assigning-non-slot/bad.py +++ b/doc/data/messages/a/assigning-non-slot/bad.py @@ -1,5 +1,5 @@ class Student: - __slots__ = ('name',) + __slots__ = ("name",) def __init__(self, name, surname): self.name = name diff --git a/doc/data/messages/a/assigning-non-slot/good.py b/doc/data/messages/a/assigning-non-slot/good.py index feb5a10fa..733728618 100644 --- a/doc/data/messages/a/assigning-non-slot/good.py +++ b/doc/data/messages/a/assigning-non-slot/good.py @@ -1,5 +1,5 @@ class Student: - __slots__ = ('name', 'surname') + __slots__ = ("name", "surname") def __init__(self, name, surname): self.name = name diff --git a/doc/data/messages/b/bad-chained-comparison/bad.py b/doc/data/messages/b/bad-chained-comparison/bad.py index eeca75f13..09e3ab627 100644 --- a/doc/data/messages/b/bad-chained-comparison/bad.py +++ b/doc/data/messages/b/bad-chained-comparison/bad.py @@ -1,3 +1,5 @@ def xor_check(*, left=None, right=None): if left is None != right is None: # [bad-chained-comparison] - raise ValueError('Either both left= and right= need to be provided or none should.') + raise ValueError( + "Either both left= and right= need to be provided or none should." + ) diff --git a/doc/data/messages/b/bad-chained-comparison/good.py b/doc/data/messages/b/bad-chained-comparison/good.py index 115f4a9db..79bb64151 100644 --- a/doc/data/messages/b/bad-chained-comparison/good.py +++ b/doc/data/messages/b/bad-chained-comparison/good.py @@ -1,3 +1,5 @@ def xor_check(*, left=None, right=None): if (left is None) != (right is None): - raise ValueError('Either both left= and right= need to be provided or none should.') + raise ValueError( + "Either both left= and right= need to be provided or none should." + ) diff --git a/doc/data/messages/b/bad-classmethod-argument/bad.py b/doc/data/messages/b/bad-classmethod-argument/bad.py index 7e43001b5..b8c6d02a0 100644 --- a/doc/data/messages/b/bad-classmethod-argument/bad.py +++ b/doc/data/messages/b/bad-classmethod-argument/bad.py @@ -1,5 +1,4 @@ class Klass: - @classmethod def get_instance(self): # [bad-classmethod-argument] return self() diff --git a/doc/data/messages/b/bad-classmethod-argument/good.py b/doc/data/messages/b/bad-classmethod-argument/good.py index 3d4decea3..6097f1e36 100644 --- a/doc/data/messages/b/bad-classmethod-argument/good.py +++ b/doc/data/messages/b/bad-classmethod-argument/good.py @@ -1,5 +1,4 @@ class Klass: - @classmethod def get_instance(cls): return cls() diff --git a/doc/data/messages/b/bad-docstring-quotes/bad.py b/doc/data/messages/b/bad-docstring-quotes/bad.py index 561921db0..bd800a40c 100644 --- a/doc/data/messages/b/bad-docstring-quotes/bad.py +++ b/doc/data/messages/b/bad-docstring-quotes/bad.py @@ -1,3 +1,3 @@ def foo(): # [bad-docstring-quotes] - 'Docstring.' + "Docstring." return diff --git a/doc/data/messages/b/bad-format-string/bad.py b/doc/data/messages/b/bad-format-string/bad.py index 523b8fba8..4cb811261 100644 --- a/doc/data/messages/b/bad-format-string/bad.py +++ b/doc/data/messages/b/bad-format-string/bad.py @@ -1 +1 @@ -print('{a[0] + a[1]}'.format(a=[0, 1])) # [bad-format-string] +print("{a[0] + a[1]}".format(a=[0, 1])) # [bad-format-string] diff --git a/doc/data/messages/b/bad-format-string/good.py b/doc/data/messages/b/bad-format-string/good.py index f2d8919b0..10475fd67 100644 --- a/doc/data/messages/b/bad-format-string/good.py +++ b/doc/data/messages/b/bad-format-string/good.py @@ -1 +1 @@ -print('{a[0]} + {a[1]}'.format(a=[0, 1])) +print("{a[0]} + {a[1]}".format(a=[0, 1])) diff --git a/doc/data/messages/b/bad-indentation/good.py b/doc/data/messages/b/bad-indentation/good.py index 1a1f33c11..e7ba80a56 100644 --- a/doc/data/messages/b/bad-indentation/good.py +++ b/doc/data/messages/b/bad-indentation/good.py @@ -1,2 +1,2 @@ if input(): - print('yes') + print("yes") diff --git a/doc/data/messages/b/bad-thread-instantiation/bad.py b/doc/data/messages/b/bad-thread-instantiation/bad.py index 580786d85..20fa72f5a 100644 --- a/doc/data/messages/b/bad-thread-instantiation/bad.py +++ b/doc/data/messages/b/bad-thread-instantiation/bad.py @@ -2,7 +2,7 @@ import threading def thread_target(n): - print(n ** 2) + print(n**2) thread = threading.Thread(lambda: None) # [bad-thread-instantiation] diff --git a/doc/data/messages/b/bad-thread-instantiation/good.py b/doc/data/messages/b/bad-thread-instantiation/good.py index 735fa4da1..0dce7c342 100644 --- a/doc/data/messages/b/bad-thread-instantiation/good.py +++ b/doc/data/messages/b/bad-thread-instantiation/good.py @@ -2,7 +2,7 @@ import threading def thread_target(n): - print(n ** 2) + print(n**2) thread = threading.Thread(target=thread_target, args=(10,)) diff --git a/doc/data/messages/c/cell-var-from-loop/bad.py b/doc/data/messages/c/cell-var-from-loop/bad.py index 9dbd43880..b31934189 100644 --- a/doc/data/messages/c/cell-var-from-loop/bad.py +++ b/doc/data/messages/c/cell-var-from-loop/bad.py @@ -1,5 +1,7 @@ def foo(numbers): for i in numbers: + def bar(): print(i) # [cell-var-from-loop] + bar() diff --git a/doc/data/messages/c/class-variable-slots-conflict/good.py b/doc/data/messages/c/class-variable-slots-conflict/good.py index b5324bff0..2428f7866 100644 --- a/doc/data/messages/c/class-variable-slots-conflict/good.py +++ b/doc/data/messages/c/class-variable-slots-conflict/good.py @@ -1,5 +1,5 @@ class Person: - __slots__ = ("_age", "name",) + __slots__ = ("_age", "name") def __init__(self, age, name): self._age = age diff --git a/doc/data/messages/c/compare-to-zero/bad.py b/doc/data/messages/c/compare-to-zero/bad.py index a6b64a407..c987403a4 100644 --- a/doc/data/messages/c/compare-to-zero/bad.py +++ b/doc/data/messages/c/compare-to-zero/bad.py @@ -1,8 +1,8 @@ x = 0 y = 1 -if x == 0: # [compare-to-zero] +if x == 0: # [compare-to-zero] print("x is equal to zero") -if y != 0: # [compare-to-zero] +if y != 0: # [compare-to-zero] print("y is not equal to zero") diff --git a/doc/data/messages/c/comparison-with-callable/bad.py b/doc/data/messages/c/comparison-with-callable/bad.py index 9dc5ecd92..1dbdad07c 100644 --- a/doc/data/messages/c/comparison-with-callable/bad.py +++ b/doc/data/messages/c/comparison-with-callable/bad.py @@ -1,6 +1,7 @@ def function_returning_a_fruit() -> str: return "orange" + def is_an_orange(fruit: str = "apple"): # apple == return fruit == function_returning_a_fruit # [comparison-with-callable] diff --git a/doc/data/messages/c/comparison-with-callable/good.py b/doc/data/messages/c/comparison-with-callable/good.py index 587cf1b98..a49007128 100644 --- a/doc/data/messages/c/comparison-with-callable/good.py +++ b/doc/data/messages/c/comparison-with-callable/good.py @@ -1,6 +1,7 @@ def function_returning_a_fruit() -> str: return "orange" + def is_an_orange(fruit: str = "apple"): # apple == orange return fruit == function_returning_a_fruit() diff --git a/doc/data/messages/c/confusing-with-statement/bad.py b/doc/data/messages/c/confusing-with-statement/bad.py index d84288058..e6570a5aa 100644 --- a/doc/data/messages/c/confusing-with-statement/bad.py +++ b/doc/data/messages/c/confusing-with-statement/bad.py @@ -1,2 +1,2 @@ -with open('file.txt', 'w') as fh1, fh2: # [confusing-with-statement] +with open("file.txt", "w") as fh1, fh2: # [confusing-with-statement] pass diff --git a/doc/data/messages/c/confusing-with-statement/good.py b/doc/data/messages/c/confusing-with-statement/good.py index e8b39d500..bcedaafa6 100644 --- a/doc/data/messages/c/confusing-with-statement/good.py +++ b/doc/data/messages/c/confusing-with-statement/good.py @@ -1,3 +1,3 @@ -with open('file.txt', 'w', encoding="utf8") as fh1: - with open('file.txt', 'w', encoding="utf8") as fh2: +with open("file.txt", "w", encoding="utf8") as fh1: + with open("file.txt", "w", encoding="utf8") as fh2: pass diff --git a/doc/data/messages/c/consider-merging-isinstance/bad.py b/doc/data/messages/c/consider-merging-isinstance/bad.py index dca0ecf05..c7b059cb4 100644 --- a/doc/data/messages/c/consider-merging-isinstance/bad.py +++ b/doc/data/messages/c/consider-merging-isinstance/bad.py @@ -2,4 +2,5 @@ from typing import Any def is_number(value: Any) -> bool: - return isinstance(value, int) or isinstance(value, float) # [consider-merging-isinstance] + # +1: [consider-merging-isinstance] + return isinstance(value, int) or isinstance(value, float) diff --git a/doc/data/messages/c/consider-using-any-or-all/good.py b/doc/data/messages/c/consider-using-any-or-all/good.py index 5acf18e74..71a727e57 100644 --- a/doc/data/messages/c/consider-using-any-or-all/good.py +++ b/doc/data/messages/c/consider-using-any-or-all/good.py @@ -1,8 +1,8 @@ - def any_even(items): """Return True if the list contains any even numbers""" return any(item % 2 == 0 for item in items) + def all_even(items): """Return True if the list contains all even numbers""" return all(item % 2 == 0 for item in items) diff --git a/doc/data/messages/c/consider-using-enumerate/bad.py b/doc/data/messages/c/consider-using-enumerate/bad.py index 25d7cbf6b..0beee2ecd 100644 --- a/doc/data/messages/c/consider-using-enumerate/bad.py +++ b/doc/data/messages/c/consider-using-enumerate/bad.py @@ -1,4 +1,4 @@ -seasons = ['Spring', 'Summer', 'Fall', 'Winter'] +seasons = ["Spring", "Summer", "Fall", "Winter"] for i in range(len(seasons)): # [consider-using-enumerate] print(i, seasons[i]) diff --git a/doc/data/messages/c/consider-using-enumerate/good.py b/doc/data/messages/c/consider-using-enumerate/good.py index c52c27066..b078e48cb 100644 --- a/doc/data/messages/c/consider-using-enumerate/good.py +++ b/doc/data/messages/c/consider-using-enumerate/good.py @@ -1,4 +1,4 @@ -seasons = ['Spring', 'Summer', 'Fall', 'Winter'] +seasons = ["Spring", "Summer", "Fall", "Winter"] for i, season in enumerate(seasons): print(i, season) diff --git a/doc/data/messages/c/consider-using-f-string/good.py b/doc/data/messages/c/consider-using-f-string/good.py index eec5abf0f..f7913fa44 100644 --- a/doc/data/messages/c/consider-using-f-string/good.py +++ b/doc/data/messages/c/consider-using-f-string/good.py @@ -1,3 +1,3 @@ -menu = ('eggs', 'spam', 42.4) +menu = ("eggs", "spam", 42.4) f_string_order = f"{menu[0]} and {menu[1]}: {menu[2]:0.2f} ¤" diff --git a/doc/data/messages/c/consider-using-in/bad.py b/doc/data/messages/c/consider-using-in/bad.py index 7199c1d82..81eddb7f3 100644 --- a/doc/data/messages/c/consider-using-in/bad.py +++ b/doc/data/messages/c/consider-using-in/bad.py @@ -1,2 +1,3 @@ def fruit_is_round(fruit): - return fruit == "apple" or fruit == "orange" or fruit == "melon" # [consider-using-in] + # +1: [consider-using-in] + return fruit == "apple" or fruit == "orange" or fruit == "melon" diff --git a/doc/data/messages/c/consider-using-join/bad.py b/doc/data/messages/c/consider-using-join/bad.py index c77b6f767..5d5a32fb7 100644 --- a/doc/data/messages/c/consider-using-join/bad.py +++ b/doc/data/messages/c/consider-using-join/bad.py @@ -4,4 +4,5 @@ def fruits_to_string(fruits): formatted_fruit += fruit # [consider-using-join] return formatted_fruit + print(fruits_to_string(["apple", "pear", "peach"])) diff --git a/doc/data/messages/d/deprecated-method/bad.py b/doc/data/messages/d/deprecated-method/bad.py index dd75a258a..78870f3c3 100644 --- a/doc/data/messages/d/deprecated-method/bad.py +++ b/doc/data/messages/d/deprecated-method/bad.py @@ -1,3 +1,3 @@ import logging -logging.warn("I'm coming, world !") # [deprecated-method] +logging.warn("I'm coming, world !") # [deprecated-method] diff --git a/doc/data/messages/d/dict-init-mutate/bad.py b/doc/data/messages/d/dict-init-mutate/bad.py index d6d1cfe18..d7db9c528 100644 --- a/doc/data/messages/d/dict-init-mutate/bad.py +++ b/doc/data/messages/d/dict-init-mutate/bad.py @@ -1,3 +1,3 @@ fruit_prices = {} # [dict-init-mutate] -fruit_prices['apple'] = 1 -fruit_prices['banana'] = 10 +fruit_prices["apple"] = 1 +fruit_prices["banana"] = 10 diff --git a/doc/data/messages/d/dict-iter-missing-items/bad.py b/doc/data/messages/d/dict-iter-missing-items/bad.py index ec9dbd924..52efa3ad7 100644 --- a/doc/data/messages/d/dict-iter-missing-items/bad.py +++ b/doc/data/messages/d/dict-iter-missing-items/bad.py @@ -1,3 +1,3 @@ -data = {'Paris': 2_165_423, 'New York City': 8_804_190, 'Tokyo': 13_988_129} +data = {"Paris": 2_165_423, "New York City": 8_804_190, "Tokyo": 13_988_129} for city, population in data: # [dict-iter-missing-items] print(f"{city} has population {population}.") diff --git a/doc/data/messages/d/dict-iter-missing-items/good.py b/doc/data/messages/d/dict-iter-missing-items/good.py index b94f125a3..3eb97f9e2 100644 --- a/doc/data/messages/d/dict-iter-missing-items/good.py +++ b/doc/data/messages/d/dict-iter-missing-items/good.py @@ -1,3 +1,3 @@ -data = {'Paris': 2_165_423, 'New York City': 8_804_190, 'Tokyo': 13_988_129} +data = {"Paris": 2_165_423, "New York City": 8_804_190, "Tokyo": 13_988_129} for city, population in data.items(): print(f"{city} has population {population}.") diff --git a/doc/data/messages/d/duplicate-code/bad/orange.py b/doc/data/messages/d/duplicate-code/bad/orange.py index faafce747..9be3c7b40 100644 --- a/doc/data/messages/d/duplicate-code/bad/orange.py +++ b/doc/data/messages/d/duplicate-code/bad/orange.py @@ -1,4 +1,4 @@ -class Orange: # [duplicate-code] +class Orange: # [duplicate-code] def __init__(self): self.remaining_bites = 3 diff --git a/doc/data/messages/d/duplicate-value/bad.py b/doc/data/messages/d/duplicate-value/bad.py index bf6f8ad00..975eebdae 100644 --- a/doc/data/messages/d/duplicate-value/bad.py +++ b/doc/data/messages/d/duplicate-value/bad.py @@ -1 +1 @@ -incorrect_set = {'value1', 23, 5, 'value1'} # [duplicate-value] +incorrect_set = {"value1", 23, 5, "value1"} # [duplicate-value] diff --git a/doc/data/messages/d/duplicate-value/good.py b/doc/data/messages/d/duplicate-value/good.py index c30cd7821..beeeb39b9 100644 --- a/doc/data/messages/d/duplicate-value/good.py +++ b/doc/data/messages/d/duplicate-value/good.py @@ -1 +1 @@ -correct_set = {'value1', 23, 5} +correct_set = {"value1", 23, 5} diff --git a/doc/data/messages/e/exec-used/good.py b/doc/data/messages/e/exec-used/good.py index ef9b17f3f..f3e1dd7b7 100644 --- a/doc/data/messages/e/exec-used/good.py +++ b/doc/data/messages/e/exec-used/good.py @@ -1,8 +1,9 @@ def get_user_code(name): - return input(f'Enter code to be executed please, {name}: ') + return input(f"Enter code to be executed please, {name}: ") username = "Ada" -allowed_globals = {'__builtins__' : None} -allowed_locals = {'print': print} -exec(get_user_code(username), allowed_globals, allowed_locals) # pylint: disable=exec-used +allowed_globals = {"__builtins__": None} +allowed_locals = {"print": print} +# pylint: disable-next=exec-used +exec(get_user_code(username), allowed_globals, allowed_locals) diff --git a/doc/data/messages/f/forgotten-debug-statement/bad.py b/doc/data/messages/f/forgotten-debug-statement/bad.py index 6a2a34580..e37185371 100644 --- a/doc/data/messages/f/forgotten-debug-statement/bad.py +++ b/doc/data/messages/f/forgotten-debug-statement/bad.py @@ -3,10 +3,15 @@ import pdb def find_the_treasure(clues): for clue in clues: - pdb.set_trace() # [forgotten-debug-statement] + pdb.set_trace() # [forgotten-debug-statement] if "treasure" in clue: return True return False -treasure_hunt = ["Dead Man's Chest", "X marks the spot", "The treasure is buried near the palm tree"] + +treasure_hunt = [ + "Dead Man's Chest", + "X marks the spot", + "The treasure is buried near the palm tree", +] find_the_treasure(treasure_hunt) diff --git a/doc/data/messages/f/forgotten-debug-statement/good.py b/doc/data/messages/f/forgotten-debug-statement/good.py index 21132cb47..7896ff50e 100644 --- a/doc/data/messages/f/forgotten-debug-statement/good.py +++ b/doc/data/messages/f/forgotten-debug-statement/good.py @@ -4,5 +4,10 @@ def find_the_treasure(clues): return True return False -treasure_hunt = ["Dead Man's Chest", "X marks the spot", "The treasure is buried near the palm tree"] + +treasure_hunt = [ + "Dead Man's Chest", + "X marks the spot", + "The treasure is buried near the palm tree", +] find_the_treasure(treasure_hunt) diff --git a/doc/data/messages/f/format-combined-specification/bad.py b/doc/data/messages/f/format-combined-specification/bad.py index 6a6a051f2..f530aa0d5 100644 --- a/doc/data/messages/f/format-combined-specification/bad.py +++ b/doc/data/messages/f/format-combined-specification/bad.py @@ -1 +1 @@ -print('{} {1}'.format('hello', 'world')) # [format-combined-specification] +print("{} {1}".format("hello", "world")) # [format-combined-specification] diff --git a/doc/data/messages/f/format-combined-specification/good.py b/doc/data/messages/f/format-combined-specification/good.py index 542b77507..8aaab67f2 100644 --- a/doc/data/messages/f/format-combined-specification/good.py +++ b/doc/data/messages/f/format-combined-specification/good.py @@ -1,3 +1,3 @@ -print('{0} {1}'.format('hello', 'world')) +print("{0} {1}".format("hello", "world")) # or -print('{} {}'.format('hello', 'world')) +print("{} {}".format("hello", "world")) diff --git a/doc/data/messages/i/import-outside-toplevel/bad.py b/doc/data/messages/i/import-outside-toplevel/bad.py index 54db8840d..5262ba770 100644 --- a/doc/data/messages/i/import-outside-toplevel/bad.py +++ b/doc/data/messages/i/import-outside-toplevel/bad.py @@ -1,3 +1,4 @@ def print_python_version(): import sys # [import-outside-toplevel] + print(sys.version_info) diff --git a/doc/data/messages/i/import-private-name/bad.py b/doc/data/messages/i/import-private-name/bad.py index 96a2a9fc9..e562e4928 100644 --- a/doc/data/messages/i/import-private-name/bad.py +++ b/doc/data/messages/i/import-private-name/bad.py @@ -2,6 +2,7 @@ from argparse import _AttributeHolder, _SubParsersAction # [import-private-name attr_holder = _AttributeHolder() + def add_sub_parser(sub_parsers: _SubParsersAction): - sub_parsers.add_parser('my_subparser') + sub_parsers.add_parser("my_subparser") # ... diff --git a/doc/data/messages/i/import-private-name/good.py b/doc/data/messages/i/import-private-name/good.py index 3a5599cfb..810005fea 100644 --- a/doc/data/messages/i/import-private-name/good.py +++ b/doc/data/messages/i/import-private-name/good.py @@ -4,5 +4,5 @@ from argparse import _SubParsersAction def add_sub_parser(sub_parsers: _SubParsersAction): - sub_parsers.add_parser('my_subparser') + sub_parsers.add_parser("my_subparser") # ... diff --git a/doc/data/messages/i/init-is-generator/bad.py b/doc/data/messages/i/init-is-generator/bad.py index 37c204ab2..415b94c4d 100644 --- a/doc/data/messages/i/init-is-generator/bad.py +++ b/doc/data/messages/i/init-is-generator/bad.py @@ -2,4 +2,5 @@ class Fruit: def __init__(self, worms): # [init-is-generator] yield from worms + apple = Fruit(["Fahad", "Anisha", "Tabatha"]) diff --git a/doc/data/messages/i/init-is-generator/good.py b/doc/data/messages/i/init-is-generator/good.py index 483cd46c1..1f5bf0047 100644 --- a/doc/data/messages/i/init-is-generator/good.py +++ b/doc/data/messages/i/init-is-generator/good.py @@ -5,6 +5,7 @@ class Fruit: def worms(self): yield from self.__worms + apple = Fruit(["Fahad", "Anisha", "Tabatha"]) for worm in apple.worms(): pass diff --git a/doc/data/messages/i/invalid-all-format/bad.py b/doc/data/messages/i/invalid-all-format/bad.py index 9559869a9..c89137734 100644 --- a/doc/data/messages/i/invalid-all-format/bad.py +++ b/doc/data/messages/i/invalid-all-format/bad.py @@ -1,3 +1,3 @@ -__all__ = ("CONST") # [invalid-all-format] +__all__ = "CONST" # [invalid-all-format] CONST = 42 diff --git a/doc/data/messages/i/invalid-all-object/bad.py b/doc/data/messages/i/invalid-all-object/bad.py index 74cf738dc..04509727b 100644 --- a/doc/data/messages/i/invalid-all-object/bad.py +++ b/doc/data/messages/i/invalid-all-object/bad.py @@ -4,8 +4,10 @@ __all__ = ( Worm, ) + class Fruit: pass + class Worm: pass diff --git a/doc/data/messages/i/invalid-all-object/good.py b/doc/data/messages/i/invalid-all-object/good.py index db5879cf3..351cfa1c6 100644 --- a/doc/data/messages/i/invalid-all-object/good.py +++ b/doc/data/messages/i/invalid-all-object/good.py @@ -1,7 +1,9 @@ -__all__ = ['Fruit', 'Worm'] +__all__ = ["Fruit", "Worm"] + class Fruit: pass + class Worm: pass diff --git a/doc/data/messages/i/invalid-character-backspace/bad.py b/doc/data/messages/i/invalid-character-backspace/bad.py index a41d6b2bc..ac9ed67a3 100644 --- a/doc/data/messages/i/invalid-character-backspace/bad.py +++ b/doc/data/messages/i/invalid-character-backspace/bad.py @@ -1 +1 @@ -STRING = "Invalid character backspace " # [invalid-character-backspace] +STRING = "Invalid character backspace " # [invalid-character-backspace] diff --git a/doc/data/messages/i/invalid-character-esc/bad.py b/doc/data/messages/i/invalid-character-esc/bad.py index 24c6a79ea..0d50cab42 100644 --- a/doc/data/messages/i/invalid-character-esc/bad.py +++ b/doc/data/messages/i/invalid-character-esc/bad.py @@ -1 +1 @@ -STRING = "Invalid escape character " # [invalid-character-esc] +STRING = "Invalid escape character " # [invalid-character-esc] diff --git a/doc/data/messages/i/invalid-character-sub/bad.py b/doc/data/messages/i/invalid-character-sub/bad.py index 96f8c06fe..313066d3b 100644 --- a/doc/data/messages/i/invalid-character-sub/bad.py +++ b/doc/data/messages/i/invalid-character-sub/bad.py @@ -1 +1 @@ -STRING = "Invalid character sub " # [invalid-character-sub] +STRING = "Invalid character sub " # [invalid-character-sub] diff --git a/doc/data/messages/i/invalid-character-zero-width-space/bad.py b/doc/data/messages/i/invalid-character-zero-width-space/bad.py index 1854893b4..99160fc8f 100644 --- a/doc/data/messages/i/invalid-character-zero-width-space/bad.py +++ b/doc/data/messages/i/invalid-character-zero-width-space/bad.py @@ -1 +1 @@ -STRING = "Invalid character zero-width-space ​" # [invalid-character-zero-width-space] +STRING = "Invalid character zero-width-space ​" # [invalid-character-zero-width-space] diff --git a/doc/data/messages/i/invalid-envvar-default/bad.py b/doc/data/messages/i/invalid-envvar-default/bad.py index 8d66765ee..9b564b9c8 100644 --- a/doc/data/messages/i/invalid-envvar-default/bad.py +++ b/doc/data/messages/i/invalid-envvar-default/bad.py @@ -1,3 +1,3 @@ import os -env = os.getenv('SECRET_KEY', 1) # [invalid-envvar-default] +env = os.getenv("SECRET_KEY", 1) # [invalid-envvar-default] diff --git a/doc/data/messages/i/invalid-envvar-default/good.py b/doc/data/messages/i/invalid-envvar-default/good.py index 67656d04a..103925941 100644 --- a/doc/data/messages/i/invalid-envvar-default/good.py +++ b/doc/data/messages/i/invalid-envvar-default/good.py @@ -1,3 +1,3 @@ import os -env = os.getenv('SECRET_KEY', '1') +env = os.getenv("SECRET_KEY", "1") diff --git a/doc/data/messages/i/invalid-envvar-value/good.py b/doc/data/messages/i/invalid-envvar-value/good.py index 0b510db39..fd082ecfd 100644 --- a/doc/data/messages/i/invalid-envvar-value/good.py +++ b/doc/data/messages/i/invalid-envvar-value/good.py @@ -1,3 +1,3 @@ import os -os.getenv('1') +os.getenv("1") diff --git a/doc/data/messages/i/invalid-format-index/good.py b/doc/data/messages/i/invalid-format-index/good.py index 37129745b..69557980b 100644 --- a/doc/data/messages/i/invalid-format-index/good.py +++ b/doc/data/messages/i/invalid-format-index/good.py @@ -1,2 +1,2 @@ enough_fruits = ["apple", "banana"] -print('The second fruit is a {fruits[1]}'.format(fruits=enough_fruits)) +print("The second fruit is a {fruits[1]}".format(fruits=enough_fruits)) diff --git a/doc/data/messages/i/invalid-length-returned/bad.py b/doc/data/messages/i/invalid-length-returned/bad.py index 0dcac176c..2ae1396c3 100644 --- a/doc/data/messages/i/invalid-length-returned/bad.py +++ b/doc/data/messages/i/invalid-length-returned/bad.py @@ -3,4 +3,4 @@ class FruitBasket: self.fruits = ["Apple", "Banana", "Orange"] def __len__(self): # [invalid-length-returned] - return - len(self.fruits) + return -len(self.fruits) diff --git a/doc/data/messages/i/invalid-metaclass/good.py b/doc/data/messages/i/invalid-metaclass/good.py index e8b90fc01..07c907f10 100644 --- a/doc/data/messages/i/invalid-metaclass/good.py +++ b/doc/data/messages/i/invalid-metaclass/good.py @@ -1,5 +1,6 @@ class Plant: pass + class Apple(Plant): pass diff --git a/doc/data/messages/i/invalid-name/bad.py b/doc/data/messages/i/invalid-name/bad.py index fac9b4947..b40ee4746 100644 --- a/doc/data/messages/i/invalid-name/bad.py +++ b/doc/data/messages/i/invalid-name/bad.py @@ -1,5 +1,4 @@ class cat: # [invalid-name] - def Meow(self, NUMBER_OF_MEOW): # [invalid-name, invalid-name] print("Meow" * NUMBER_OF_MEOW) return NUMBER_OF_MEOW diff --git a/doc/data/messages/i/invalid-name/good.py b/doc/data/messages/i/invalid-name/good.py index 3decdb3e4..d747a72f0 100644 --- a/doc/data/messages/i/invalid-name/good.py +++ b/doc/data/messages/i/invalid-name/good.py @@ -1,5 +1,4 @@ class Cat: - def meow(self, number_of_meow): print("Meow" * number_of_meow) return number_of_meow diff --git a/doc/data/messages/i/invalid-overridden-method/bad.py b/doc/data/messages/i/invalid-overridden-method/bad.py index 379f7c0a1..c7e250fb5 100644 --- a/doc/data/messages/i/invalid-overridden-method/bad.py +++ b/doc/data/messages/i/invalid-overridden-method/bad.py @@ -2,6 +2,7 @@ class Fruit: async def bore(self, insect): insect.eat(self) + class Apple(Fruit): def bore(self, insect): # [invalid-overridden-method] insect.eat(self) diff --git a/doc/data/messages/i/invalid-overridden-method/good.py b/doc/data/messages/i/invalid-overridden-method/good.py index f5b56308f..320663778 100644 --- a/doc/data/messages/i/invalid-overridden-method/good.py +++ b/doc/data/messages/i/invalid-overridden-method/good.py @@ -2,6 +2,7 @@ class Fruit: async def bore(self, insect): insect.eat(self) + class Apple(Fruit): async def bore(self, insect): insect.eat(self) diff --git a/doc/data/messages/i/invalid-sequence-index/bad.py b/doc/data/messages/i/invalid-sequence-index/bad.py index f153503b9..c13a3742a 100644 --- a/doc/data/messages/i/invalid-sequence-index/bad.py +++ b/doc/data/messages/i/invalid-sequence-index/bad.py @@ -1,2 +1,2 @@ -fruits = ['apple', 'banana', 'orange'] -print(fruits['apple']) # [invalid-sequence-index] +fruits = ["apple", "banana", "orange"] +print(fruits["apple"]) # [invalid-sequence-index] diff --git a/doc/data/messages/i/invalid-sequence-index/good.py b/doc/data/messages/i/invalid-sequence-index/good.py index 04bdf3ffd..840f3c3f3 100644 --- a/doc/data/messages/i/invalid-sequence-index/good.py +++ b/doc/data/messages/i/invalid-sequence-index/good.py @@ -1,2 +1,2 @@ -fruits = ['apple', 'banana', 'orange'] +fruits = ["apple", "banana", "orange"] print(fruits[0]) diff --git a/doc/data/messages/i/invalid-slots-object/bad.py b/doc/data/messages/i/invalid-slots-object/bad.py index 41baaa54f..03690cf36 100644 --- a/doc/data/messages/i/invalid-slots-object/bad.py +++ b/doc/data/messages/i/invalid-slots-object/bad.py @@ -1,2 +1,2 @@ class Person: - __slots__ = ('name', 3) # [invalid-slots-object] + __slots__ = ("name", 3) # [invalid-slots-object] diff --git a/doc/data/messages/i/invalid-slots-object/good.py b/doc/data/messages/i/invalid-slots-object/good.py index e8eec6949..823a971f1 100644 --- a/doc/data/messages/i/invalid-slots-object/good.py +++ b/doc/data/messages/i/invalid-slots-object/good.py @@ -1,2 +1,2 @@ class Person: - __slots__ = ('name', 'surname') + __slots__ = ("name", "surname") diff --git a/doc/data/messages/i/invalid-slots/good.py b/doc/data/messages/i/invalid-slots/good.py index 0cb4d1b1e..b7881356c 100644 --- a/doc/data/messages/i/invalid-slots/good.py +++ b/doc/data/messages/i/invalid-slots/good.py @@ -1,2 +1,2 @@ class Person: - __slots__ = ("name", "age",) + __slots__ = ("name", "age") diff --git a/doc/data/messages/i/invalid-star-assignment-target/bad.py b/doc/data/messages/i/invalid-star-assignment-target/bad.py index fc69dc7e6..476928560 100644 --- a/doc/data/messages/i/invalid-star-assignment-target/bad.py +++ b/doc/data/messages/i/invalid-star-assignment-target/bad.py @@ -1 +1 @@ -*fruit = ['apple', 'banana', 'orange'] # [invalid-star-assignment-target] +*fruit = ["apple", "banana", "orange"] # [invalid-star-assignment-target] diff --git a/doc/data/messages/i/invalid-star-assignment-target/good.py b/doc/data/messages/i/invalid-star-assignment-target/good.py index 74cf088e2..b174bcd20 100644 --- a/doc/data/messages/i/invalid-star-assignment-target/good.py +++ b/doc/data/messages/i/invalid-star-assignment-target/good.py @@ -1 +1 @@ -fruit = ['apple', 'banana', 'orange'] +fruit = ["apple", "banana", "orange"] diff --git a/doc/data/messages/i/invalid-unary-operand-type/bad.py b/doc/data/messages/i/invalid-unary-operand-type/bad.py index 77391c3d9..b01195194 100644 --- a/doc/data/messages/i/invalid-unary-operand-type/bad.py +++ b/doc/data/messages/i/invalid-unary-operand-type/bad.py @@ -1,3 +1,3 @@ cherries = 10 eaten_cherries = int -cherries = - eaten_cherries # [invalid-unary-operand-type] +cherries = -eaten_cherries # [invalid-unary-operand-type] diff --git a/doc/data/messages/l/locally-disabled/bad.py b/doc/data/messages/l/locally-disabled/bad.py index 5bfbd58f8..1a3307856 100644 --- a/doc/data/messages/l/locally-disabled/bad.py +++ b/doc/data/messages/l/locally-disabled/bad.py @@ -3,5 +3,6 @@ def wizard_spells(spell_book): for spell in spell_book: print(f"Abracadabra! {spell}.") + spell_list = ["Levitation", "Invisibility", "Fireball", "Teleportation"] wizard_spells(spell_list) diff --git a/doc/data/messages/l/locally-disabled/good.py b/doc/data/messages/l/locally-disabled/good.py index 322a78f27..1bf60bca0 100644 --- a/doc/data/messages/l/locally-disabled/good.py +++ b/doc/data/messages/l/locally-disabled/good.py @@ -2,5 +2,6 @@ def wizard_spells(spell_book): for spell in spell_book: print(f"Abracadabra! {spell}.") + spell_list = ["Levitation", "Invisibility", "Fireball", "Teleportation"] wizard_spells(spell_list) diff --git a/doc/data/messages/l/logging-format-interpolation/bad.py b/doc/data/messages/l/logging-format-interpolation/bad.py index 0cef831d2..dd828e1f9 100644 --- a/doc/data/messages/l/logging-format-interpolation/bad.py +++ b/doc/data/messages/l/logging-format-interpolation/bad.py @@ -1,4 +1,5 @@ import logging import sys -logging.error('Python version: {}'.format(sys.version)) # [logging-format-interpolation] +# +1: [logging-format-interpolation] +logging.error("Python version: {}".format(sys.version)) diff --git a/doc/data/messages/l/logging-format-interpolation/good.py b/doc/data/messages/l/logging-format-interpolation/good.py index 7f54cebfb..a993d0dd8 100644 --- a/doc/data/messages/l/logging-format-interpolation/good.py +++ b/doc/data/messages/l/logging-format-interpolation/good.py @@ -1,4 +1,4 @@ import logging import sys -logging.error('Python version: %s', sys.version) +logging.error("Python version: %s", sys.version) diff --git a/doc/data/messages/l/logging-fstring-interpolation/bad.py b/doc/data/messages/l/logging-fstring-interpolation/bad.py index dfee6d4c6..773435fb4 100644 --- a/doc/data/messages/l/logging-fstring-interpolation/bad.py +++ b/doc/data/messages/l/logging-fstring-interpolation/bad.py @@ -1,4 +1,4 @@ import logging import sys -logging.error(f'Python version: {sys.version}') # [logging-fstring-interpolation] +logging.error(f"Python version: {sys.version}") # [logging-fstring-interpolation] diff --git a/doc/data/messages/l/logging-fstring-interpolation/good.py b/doc/data/messages/l/logging-fstring-interpolation/good.py index 7f54cebfb..a993d0dd8 100644 --- a/doc/data/messages/l/logging-fstring-interpolation/good.py +++ b/doc/data/messages/l/logging-fstring-interpolation/good.py @@ -1,4 +1,4 @@ import logging import sys -logging.error('Python version: %s', sys.version) +logging.error("Python version: %s", sys.version) diff --git a/doc/data/messages/l/logging-not-lazy/bad.py b/doc/data/messages/l/logging-not-lazy/bad.py index cb6bc3d84..7ba0631db 100644 --- a/doc/data/messages/l/logging-not-lazy/bad.py +++ b/doc/data/messages/l/logging-not-lazy/bad.py @@ -3,5 +3,5 @@ import logging try: function() except Exception as e: - logging.error('Error occurred: %s' % e) # [logging-not-lazy] + logging.error("Error occurred: %s" % e) # [logging-not-lazy] raise diff --git a/doc/data/messages/l/logging-not-lazy/good.py b/doc/data/messages/l/logging-not-lazy/good.py index c61704872..ede0050cb 100644 --- a/doc/data/messages/l/logging-not-lazy/good.py +++ b/doc/data/messages/l/logging-not-lazy/good.py @@ -3,5 +3,5 @@ import logging try: function() except Exception as e: - logging.error('Error occurred: %s', e) + logging.error("Error occurred: %s", e) raise diff --git a/doc/data/messages/l/logging-too-few-args/bad.py b/doc/data/messages/l/logging-too-few-args/bad.py index 66d88d0b3..a20b83b12 100644 --- a/doc/data/messages/l/logging-too-few-args/bad.py +++ b/doc/data/messages/l/logging-too-few-args/bad.py @@ -3,5 +3,5 @@ import logging try: function() except Exception as e: - logging.error('%s error occurred: %s', e) # [logging-too-few-args] + logging.error("%s error occurred: %s", e) # [logging-too-few-args] raise diff --git a/doc/data/messages/l/logging-too-few-args/good.py b/doc/data/messages/l/logging-too-few-args/good.py index 4b34b58b9..4812aec01 100644 --- a/doc/data/messages/l/logging-too-few-args/good.py +++ b/doc/data/messages/l/logging-too-few-args/good.py @@ -3,5 +3,5 @@ import logging try: function() except Exception as e: - logging.error('%s error occurred: %s', type(e), e) + logging.error("%s error occurred: %s", type(e), e) raise diff --git a/doc/data/messages/l/logging-too-many-args/bad.py b/doc/data/messages/l/logging-too-many-args/bad.py index 45f485d93..03753f607 100644 --- a/doc/data/messages/l/logging-too-many-args/bad.py +++ b/doc/data/messages/l/logging-too-many-args/bad.py @@ -3,5 +3,5 @@ import logging try: function() except Exception as e: - logging.error('Error occurred: %s', type(e), e) # [logging-too-many-args] + logging.error("Error occurred: %s", type(e), e) # [logging-too-many-args] raise diff --git a/doc/data/messages/l/logging-too-many-args/good.py b/doc/data/messages/l/logging-too-many-args/good.py index 4b34b58b9..4812aec01 100644 --- a/doc/data/messages/l/logging-too-many-args/good.py +++ b/doc/data/messages/l/logging-too-many-args/good.py @@ -3,5 +3,5 @@ import logging try: function() except Exception as e: - logging.error('%s error occurred: %s', type(e), e) + logging.error("%s error occurred: %s", type(e), e) raise diff --git a/doc/data/messages/l/logging-unsupported-format/bad.py b/doc/data/messages/l/logging-unsupported-format/bad.py index 5b5ea5a5f..1f36a0d34 100644 --- a/doc/data/messages/l/logging-unsupported-format/bad.py +++ b/doc/data/messages/l/logging-unsupported-format/bad.py @@ -1,3 +1,3 @@ import logging -logging.info("%s %y !", "Hello", "World") # [logging-unsupported-format] +logging.info("%s %y !", "Hello", "World") # [logging-unsupported-format] diff --git a/doc/data/messages/m/magic-value-comparison/bad.py b/doc/data/messages/m/magic-value-comparison/bad.py index 536659abe..eef9e5d27 100644 --- a/doc/data/messages/m/magic-value-comparison/bad.py +++ b/doc/data/messages/m/magic-value-comparison/bad.py @@ -3,8 +3,8 @@ import random measurement = random.randint(0, 200) above_threshold = False i = 0 -while i < 5: # [magic-value-comparison] - above_threshold = measurement > 100 # [magic-value-comparison] +while i < 5: # [magic-value-comparison] + above_threshold = measurement > 100 # [magic-value-comparison] if above_threshold: break measurement = random.randint(0, 200) diff --git a/doc/data/messages/m/misplaced-format-function/bad.py b/doc/data/messages/m/misplaced-format-function/bad.py index 0bd172369..bc40bba4d 100644 --- a/doc/data/messages/m/misplaced-format-function/bad.py +++ b/doc/data/messages/m/misplaced-format-function/bad.py @@ -1 +1 @@ -print('Value: {}').format('Car') # [misplaced-format-function] +print("Value: {}").format("Car") # [misplaced-format-function] diff --git a/doc/data/messages/m/misplaced-format-function/good.py b/doc/data/messages/m/misplaced-format-function/good.py index 809dcf974..8b31d5cf5 100644 --- a/doc/data/messages/m/misplaced-format-function/good.py +++ b/doc/data/messages/m/misplaced-format-function/good.py @@ -1 +1 @@ -print('Value: {}'.format('Car')) +print("Value: {}".format("Car")) diff --git a/doc/data/messages/m/missing-any-param-doc/bad.py b/doc/data/messages/m/missing-any-param-doc/bad.py index ca92793f5..bf5f232ce 100644 --- a/doc/data/messages/m/missing-any-param-doc/bad.py +++ b/doc/data/messages/m/missing-any-param-doc/bad.py @@ -1,3 +1,3 @@ -def puppies(head, tail): #[missing-any-param-doc] +def puppies(head, tail): # [missing-any-param-doc] """Print puppy's details.""" print(head, tail) diff --git a/doc/data/messages/m/missing-any-param-doc/good.py b/doc/data/messages/m/missing-any-param-doc/good.py index 238ea1bce..6fa9622ee 100644 --- a/doc/data/messages/m/missing-any-param-doc/good.py +++ b/doc/data/messages/m/missing-any-param-doc/good.py @@ -1,7 +1,7 @@ def puppies(head: str, tail: str): """Print puppy's details. - :param head: description of the head of the dog - :param tail: description of the tail of the dog + :param head: description of the head of the dog + :param tail: description of the tail of the dog """ print(head, tail) diff --git a/doc/data/messages/m/missing-class-docstring/bad.py b/doc/data/messages/m/missing-class-docstring/bad.py index 1d0f79c75..e3e1ddbf5 100644 --- a/doc/data/messages/m/missing-class-docstring/bad.py +++ b/doc/data/messages/m/missing-class-docstring/bad.py @@ -1,5 +1,4 @@ class Person: # [missing-class-docstring] - def __init__(self, first_name, last_name): self.first_name = first_name self.last_name = last_name diff --git a/doc/data/messages/m/missing-final-newline/good.py b/doc/data/messages/m/missing-final-newline/good.py index fa1e5072e..02d068916 100644 --- a/doc/data/messages/m/missing-final-newline/good.py +++ b/doc/data/messages/m/missing-final-newline/good.py @@ -1,6 +1,6 @@ # using LF -eat("apple", "candy") # \n +eat("apple", "candy") # \n print(123) # \nEOF # using CRLF diff --git a/doc/data/messages/m/missing-kwoa/bad.py b/doc/data/messages/m/missing-kwoa/bad.py index 4039c8ff2..2b8deabdf 100644 --- a/doc/data/messages/m/missing-kwoa/bad.py +++ b/doc/data/messages/m/missing-kwoa/bad.py @@ -1,5 +1,6 @@ def target(pos, *, keyword): return pos + keyword + def not_forwarding_kwargs(*args, **kwargs): - target(*args) # [missing-kwoa] + target(*args) # [missing-kwoa] diff --git a/doc/data/messages/m/missing-kwoa/good.py b/doc/data/messages/m/missing-kwoa/good.py index abb80a118..c212deb98 100644 --- a/doc/data/messages/m/missing-kwoa/good.py +++ b/doc/data/messages/m/missing-kwoa/good.py @@ -1,5 +1,6 @@ def target(pos, *, keyword): return pos + keyword + def not_forwarding_kwargs(*args, **kwargs): target(*args, **kwargs) diff --git a/doc/data/messages/m/missing-parentheses-for-call-in-test/bad.py b/doc/data/messages/m/missing-parentheses-for-call-in-test/bad.py index 3f67322dc..e4a7172a4 100644 --- a/doc/data/messages/m/missing-parentheses-for-call-in-test/bad.py +++ b/doc/data/messages/m/missing-parentheses-for-call-in-test/bad.py @@ -4,5 +4,6 @@ import random def is_it_a_good_day(): return random.choice([True, False]) + if is_it_a_good_day: # [missing-parentheses-for-call-in-test] print("Today is a good day!") diff --git a/doc/data/messages/m/missing-parentheses-for-call-in-test/good.py b/doc/data/messages/m/missing-parentheses-for-call-in-test/good.py index 63c8ccc89..80afd7769 100644 --- a/doc/data/messages/m/missing-parentheses-for-call-in-test/good.py +++ b/doc/data/messages/m/missing-parentheses-for-call-in-test/good.py @@ -4,5 +4,6 @@ import random def is_it_a_good_day(): return random.choice([True, False]) + if is_it_a_good_day(): print("Today is a good day!") diff --git a/doc/data/messages/m/missing-raises-doc/bad.py b/doc/data/messages/m/missing-raises-doc/bad.py index 9a59fea88..51efd3910 100644 --- a/doc/data/messages/m/missing-raises-doc/bad.py +++ b/doc/data/messages/m/missing-raises-doc/bad.py @@ -4,5 +4,5 @@ def integer_sum(a: int, b: int): # [missing-raises-doc] :param b: second integer """ if not (isinstance(a, int) and isinstance(b, int)): - raise ValueError('Function supports only integer parameters.') + raise ValueError("Function supports only integer parameters.") return a + b diff --git a/doc/data/messages/m/missing-raises-doc/good.py b/doc/data/messages/m/missing-raises-doc/good.py index c274493ea..6ca44d0fd 100644 --- a/doc/data/messages/m/missing-raises-doc/good.py +++ b/doc/data/messages/m/missing-raises-doc/good.py @@ -5,5 +5,5 @@ def integer_sum(a: int, b: int): :raises ValueError: One of the parameters is not an integer. """ if not (isinstance(a, int) and isinstance(b, int)): - raise ValueError('Function supports only integer parameters.') + raise ValueError("Function supports only integer parameters.") return a + b diff --git a/doc/data/messages/n/named-expr-without-context/good.py b/doc/data/messages/n/named-expr-without-context/good.py index 50f6b2621..fb088bb99 100644 --- a/doc/data/messages/n/named-expr-without-context/good.py +++ b/doc/data/messages/n/named-expr-without-context/good.py @@ -1,2 +1,2 @@ -if (a := 42): - print('Success') +if a := 42: + print("Success") diff --git a/doc/data/messages/n/no-else-continue/bad.py b/doc/data/messages/n/no-else-continue/bad.py index 5e3172947..a561f93cc 100644 --- a/doc/data/messages/n/no-else-continue/bad.py +++ b/doc/data/messages/n/no-else-continue/bad.py @@ -1,6 +1,6 @@ def even_number_under(n: int): for i in range(n): - if i%2 == 1: # [no-else-continue] + if i % 2 == 1: # [no-else-continue] continue else: yield i diff --git a/doc/data/messages/n/no-else-continue/good.py b/doc/data/messages/n/no-else-continue/good.py index 8aaef7014..e73e0e21c 100644 --- a/doc/data/messages/n/no-else-continue/good.py +++ b/doc/data/messages/n/no-else-continue/good.py @@ -1,5 +1,5 @@ def even_number_under(n: int): for i in range(n): - if i%2 == 1: + if i % 2 == 1: continue yield i diff --git a/doc/data/messages/n/no-else-raise/bad.py b/doc/data/messages/n/no-else-raise/bad.py index d2f590ab8..c5fdf996e 100644 --- a/doc/data/messages/n/no-else-raise/bad.py +++ b/doc/data/messages/n/no-else-raise/bad.py @@ -1,5 +1,5 @@ def integer_sum(a: int, b: int) -> int: - if not (isinstance(a, int) and isinstance(b, int)): # [no-else-raise] - raise ValueError('Function supports only integer parameters.') + if not (isinstance(a, int) and isinstance(b, int)): # [no-else-raise] + raise ValueError("Function supports only integer parameters.") else: return a + b diff --git a/doc/data/messages/n/no-else-raise/good.py b/doc/data/messages/n/no-else-raise/good.py index c0d577cfa..bf2918148 100644 --- a/doc/data/messages/n/no-else-raise/good.py +++ b/doc/data/messages/n/no-else-raise/good.py @@ -1,4 +1,4 @@ def integer_sum(a: int, b: int) -> int: if not (isinstance(a, int) and isinstance(b, int)): - raise ValueError('Function supports only integer parameters.') + raise ValueError("Function supports only integer parameters.") return a + b diff --git a/doc/data/messages/n/no-self-use/bad.py b/doc/data/messages/n/no-self-use/bad.py index 8c44a3c1e..07ab6f3ab 100644 --- a/doc/data/messages/n/no-self-use/bad.py +++ b/doc/data/messages/n/no-self-use/bad.py @@ -1,5 +1,4 @@ class Person: - def developer_greeting(self): # [no-self-use] print("Greetings developer!") diff --git a/doc/data/messages/n/no-value-for-parameter/bad.py b/doc/data/messages/n/no-value-for-parameter/bad.py index cf10d9a57..31b08a16a 100644 --- a/doc/data/messages/n/no-value-for-parameter/bad.py +++ b/doc/data/messages/n/no-value-for-parameter/bad.py @@ -1,4 +1,5 @@ def add(x, y): return x + y + add(1) # [no-value-for-parameter] diff --git a/doc/data/messages/n/no-value-for-parameter/good.py b/doc/data/messages/n/no-value-for-parameter/good.py index e14c45c21..068b52527 100644 --- a/doc/data/messages/n/no-value-for-parameter/good.py +++ b/doc/data/messages/n/no-value-for-parameter/good.py @@ -1,4 +1,5 @@ def add(x, y): return x + y + add(1, 2) diff --git a/doc/data/messages/o/overlapping-except/good.py b/doc/data/messages/o/overlapping-except/good.py index 41a727545..0cace420e 100644 --- a/doc/data/messages/o/overlapping-except/good.py +++ b/doc/data/messages/o/overlapping-except/good.py @@ -7,10 +7,14 @@ def divide_x_by_y(x: float, y: float): # FloatingPointError were already caught at this point print(f"There was an OverflowError or a ZeroDivisionError: {e}") + # Or: + def divide_x_by_y(x: float, y: float): try: print(x / y) except ArithmeticError as e: - print(f"There was an OverflowError, a ZeroDivisionError or a FloatingPointError: {e}") + print( + f"There was an OverflowError, a ZeroDivisionError or a FloatingPointError: {e}" + ) diff --git a/doc/data/messages/p/positional-only-arguments-expected/bad.py b/doc/data/messages/p/positional-only-arguments-expected/bad.py index 30720555a..75e63e572 100644 --- a/doc/data/messages/p/positional-only-arguments-expected/bad.py +++ b/doc/data/messages/p/positional-only-arguments-expected/bad.py @@ -2,4 +2,5 @@ def cube(n, /): """Takes in a number n, returns the cube of n""" return n**3 -cube(n=2) # [positional-only-arguments-expected] + +cube(n=2) # [positional-only-arguments-expected] diff --git a/doc/data/messages/p/positional-only-arguments-expected/good.py b/doc/data/messages/p/positional-only-arguments-expected/good.py index ca734e546..77cdc80a4 100644 --- a/doc/data/messages/p/positional-only-arguments-expected/good.py +++ b/doc/data/messages/p/positional-only-arguments-expected/good.py @@ -2,4 +2,5 @@ def cube(n, /): """Takes in a number n, returns the cube of n""" return n**3 + cube(2) diff --git a/doc/data/messages/r/redefined-argument-from-local/bad.py b/doc/data/messages/r/redefined-argument-from-local/bad.py index 24d441219..733f307b3 100644 --- a/doc/data/messages/r/redefined-argument-from-local/bad.py +++ b/doc/data/messages/r/redefined-argument-from-local/bad.py @@ -1,3 +1,4 @@ def show(host_id=10.11): - for host_id, host in [[12.13, 'Venus'], [14.15, 'Mars']]: # [redefined-argument-from-local] + # +1: [redefined-argument-from-local] + for host_id, host in [[12.13, "Venus"], [14.15, "Mars"]]: print(host_id, host) diff --git a/doc/data/messages/r/redefined-argument-from-local/good.py b/doc/data/messages/r/redefined-argument-from-local/good.py index 330f94f45..fd7c081ac 100644 --- a/doc/data/messages/r/redefined-argument-from-local/good.py +++ b/doc/data/messages/r/redefined-argument-from-local/good.py @@ -1,3 +1,3 @@ def show(host_id=10.11): - for inner_host_id, host in [[12.13, 'Venus'], [14.15, 'Mars']]: + for inner_host_id, host in [[12.13, "Venus"], [14.15, "Mars"]]: print(host_id, inner_host_id, host) diff --git a/doc/data/messages/r/return-in-init/bad.py b/doc/data/messages/r/return-in-init/bad.py index 70fc2d0fd..044174e0a 100644 --- a/doc/data/messages/r/return-in-init/bad.py +++ b/doc/data/messages/r/return-in-init/bad.py @@ -1,4 +1,3 @@ class Sum: - def __init__(self, a, b): # [return-in-init] return a + b diff --git a/doc/data/messages/r/return-in-init/good.py b/doc/data/messages/r/return-in-init/good.py index ef8e6e09b..0efe05af4 100644 --- a/doc/data/messages/r/return-in-init/good.py +++ b/doc/data/messages/r/return-in-init/good.py @@ -1,4 +1,3 @@ class Sum: - def __init__(self, a, b) -> None: self.result = a + b diff --git a/doc/data/messages/s/self-cls-assignment/bad.py b/doc/data/messages/s/self-cls-assignment/bad.py index 64541405f..50fe89015 100644 --- a/doc/data/messages/s/self-cls-assignment/bad.py +++ b/doc/data/messages/s/self-cls-assignment/bad.py @@ -1,7 +1,7 @@ class Fruit: @classmethod def list_fruits(cls): - cls = 'apple' # [self-cls-assignment] + cls = "apple" # [self-cls-assignment] def print_color(self, *colors): self = "red" # [self-cls-assignment] diff --git a/doc/data/messages/s/self-cls-assignment/good.py b/doc/data/messages/s/self-cls-assignment/good.py index ae8b172fa..d1960f251 100644 --- a/doc/data/messages/s/self-cls-assignment/good.py +++ b/doc/data/messages/s/self-cls-assignment/good.py @@ -1,7 +1,7 @@ class Fruit: @classmethod def list_fruits(cls): - fruit = 'apple' + fruit = "apple" print(fruit) def print_color(self, *colors): diff --git a/doc/data/messages/s/simplifiable-if-statement/bad.py b/doc/data/messages/s/simplifiable-if-statement/bad.py index 0c9fb317f..1a8d6f0f7 100644 --- a/doc/data/messages/s/simplifiable-if-statement/bad.py +++ b/doc/data/messages/s/simplifiable-if-statement/bad.py @@ -2,7 +2,8 @@ FLYING_THINGS = ["bird", "plane", "superman", "this example"] def is_flying_animal(an_object): - if isinstance(an_object, Animal) and an_object in FLYING_THINGS: # [simplifiable-if-statement] + # +1: [simplifiable-if-statement] + if isinstance(an_object, Animal) and an_object in FLYING_THINGS: is_flying = True else: is_flying = False diff --git a/doc/data/messages/s/subprocess-popen-preexec-fn/bad.py b/doc/data/messages/s/subprocess-popen-preexec-fn/bad.py index c0d3f7bfa..6be75e472 100644 --- a/doc/data/messages/s/subprocess-popen-preexec-fn/bad.py +++ b/doc/data/messages/s/subprocess-popen-preexec-fn/bad.py @@ -5,4 +5,4 @@ def foo(): pass -subprocess.Popen(preexec_fn=foo) # [subprocess-popen-preexec-fn] +subprocess.Popen(preexec_fn=foo) # [subprocess-popen-preexec-fn] diff --git a/doc/data/messages/s/syntax-error/good.py b/doc/data/messages/s/syntax-error/good.py index eccab8746..10a644f1b 100644 --- a/doc/data/messages/s/syntax-error/good.py +++ b/doc/data/messages/s/syntax-error/good.py @@ -1,5 +1 @@ -fruit_stock = { - 'apple': 42, - 'orange': 21, - 'banana': 12 -} +fruit_stock = {"apple": 42, "orange": 21, "banana": 12} diff --git a/doc/data/messages/t/too-few-public-methods/good.py b/doc/data/messages/t/too-few-public-methods/good.py index ca4b5b6fb..b0de1ef75 100644 --- a/doc/data/messages/t/too-few-public-methods/good.py +++ b/doc/data/messages/t/too-few-public-methods/good.py @@ -12,17 +12,22 @@ class Worm: def wiggle(self): print(f"{self.name} wiggle around wormily.") + # or + @dataclasses.dataclass class Worm: - name:str + name: str fruit_of_residence: Fruit + def bore(worm: Worm): print(f"{worm.name} is boring into {worm.fruit_of_residence}") + # or + def bore(fruit: Fruit, worm_name: str): print(f"{worm_name} is boring into {fruit}") diff --git a/doc/data/messages/t/too-many-boolean-expressions/good.py b/doc/data/messages/t/too-many-boolean-expressions/good.py index 1da025460..8405d4f29 100644 --- a/doc/data/messages/t/too-many-boolean-expressions/good.py +++ b/doc/data/messages/t/too-many-boolean-expressions/good.py @@ -1,3 +1,3 @@ def can_be_divided_by_two_and_are_not_zero(x, y, z): - if all(i and i%2==0 for i in [x, y, z]): + if all(i and i % 2 == 0 for i in [x, y, z]): pass diff --git a/doc/data/messages/t/too-many-locals/bad.py b/doc/data/messages/t/too-many-locals/bad.py index dae054ed8..d2a762b49 100644 --- a/doc/data/messages/t/too-many-locals/bad.py +++ b/doc/data/messages/t/too-many-locals/bad.py @@ -20,7 +20,9 @@ def handle_sweets(infos): # [too-many-locals] # Calculate remaining money remaining_money = money - cost_of_children # Calculate time it took - time_it_took_assuming_parallel_eating = time_to_eat_sweet * number_of_sweet_per_child + time_it_took_assuming_parallel_eating = ( + time_to_eat_sweet * number_of_sweet_per_child + ) print( f"{children} ate {cost_of_children}¤ of sweets in {time_it_took_assuming_parallel_eating}, " f"you still have {remaining_money}" diff --git a/doc/data/messages/t/too-many-return-statements/bad.py b/doc/data/messages/t/too-many-return-statements/bad.py index e421d29a7..827177f1b 100644 --- a/doc/data/messages/t/too-many-return-statements/bad.py +++ b/doc/data/messages/t/too-many-return-statements/bad.py @@ -1,16 +1,16 @@ def to_string(x): # [too-many-return-statements] # max of 6 by default, can be configured if x == 1: - return 'This is one.' + return "This is one." if x == 2: - return 'This is two.' + return "This is two." if x == 3: - return 'This is three.' + return "This is three." if x == 4: - return 'This is four.' + return "This is four." if x == 5: - return 'This is five.' + return "This is five." if x == 6: - return 'This is six.' + return "This is six." if x == 7: - return 'This is seven.' + return "This is seven." diff --git a/doc/data/messages/t/too-many-return-statements/good.py b/doc/data/messages/t/too-many-return-statements/good.py index 0c4032f53..80ae2ac19 100644 --- a/doc/data/messages/t/too-many-return-statements/good.py +++ b/doc/data/messages/t/too-many-return-statements/good.py @@ -1,13 +1,13 @@ NUMBERS_TO_STRINGS = { - 1: 'one', - 2: 'two', - 3: 'three', - 4: 'four', - 5: 'five', - 6: 'six', - 7: 'seven' + 1: "one", + 2: "two", + 3: "three", + 4: "four", + 5: "five", + 6: "six", + 7: "seven", } def to_string(x): - return f'This is {NUMBERS_TO_STRINGS.get(x)}.' + return f"This is {NUMBERS_TO_STRINGS.get(x)}." diff --git a/doc/data/messages/t/truncated-format-string/bad.py b/doc/data/messages/t/truncated-format-string/bad.py index 961582bff..a44bca2f3 100644 --- a/doc/data/messages/t/truncated-format-string/bad.py +++ b/doc/data/messages/t/truncated-format-string/bad.py @@ -1,3 +1,3 @@ PARG_2 = 1 -print("strange format %2" % PARG_2) # [truncated-format-string] +print("strange format %2" % PARG_2) # [truncated-format-string] diff --git a/doc/data/messages/u/undefined-all-variable/bad.py b/doc/data/messages/u/undefined-all-variable/bad.py index dd7bef8cb..3168018d5 100644 --- a/doc/data/messages/u/undefined-all-variable/bad.py +++ b/doc/data/messages/u/undefined-all-variable/bad.py @@ -1,4 +1,5 @@ __all__ = ["get_fruit_colour"] # [undefined-all-variable] + def get_fruit_color(): pass diff --git a/doc/data/messages/u/undefined-all-variable/good.py b/doc/data/messages/u/undefined-all-variable/good.py index 3fb85e824..950222b56 100644 --- a/doc/data/messages/u/undefined-all-variable/good.py +++ b/doc/data/messages/u/undefined-all-variable/good.py @@ -1,4 +1,5 @@ __all__ = ["get_fruit_color"] + def get_fruit_color(): pass diff --git a/doc/data/messages/u/unnecessary-direct-lambda-call/bad.py b/doc/data/messages/u/unnecessary-direct-lambda-call/bad.py index 1057f8be6..280fb3b75 100644 --- a/doc/data/messages/u/unnecessary-direct-lambda-call/bad.py +++ b/doc/data/messages/u/unnecessary-direct-lambda-call/bad.py @@ -1 +1 @@ -y = (lambda x: x**2 + 2*x + 1)(a) # [unnecessary-direct-lambda-call] +y = (lambda x: x**2 + 2 * x + 1)(a) # [unnecessary-direct-lambda-call] diff --git a/doc/data/messages/u/unnecessary-direct-lambda-call/good.py b/doc/data/messages/u/unnecessary-direct-lambda-call/good.py index 1fe996f69..5870a4a23 100644 --- a/doc/data/messages/u/unnecessary-direct-lambda-call/good.py +++ b/doc/data/messages/u/unnecessary-direct-lambda-call/good.py @@ -1 +1 @@ -y = a**2 + 2*a + 1 +y = a**2 + 2 * a + 1 diff --git a/doc/data/messages/u/unnecessary-dunder-call/bad.py b/doc/data/messages/u/unnecessary-dunder-call/bad.py index 66149d772..49405d47b 100644 --- a/doc/data/messages/u/unnecessary-dunder-call/bad.py +++ b/doc/data/messages/u/unnecessary-dunder-call/bad.py @@ -1,4 +1,4 @@ -three = 3.0.__str__() # [unnecessary-dunder-call] +three = (3.0).__str__() # [unnecessary-dunder-call] twelve = "1".__add__("2") # [unnecessary-dunder-call] diff --git a/doc/data/messages/u/unnecessary-lambda-assignment/bad.py b/doc/data/messages/u/unnecessary-lambda-assignment/bad.py index b31553e4a..87e7ccdba 100644 --- a/doc/data/messages/u/unnecessary-lambda-assignment/bad.py +++ b/doc/data/messages/u/unnecessary-lambda-assignment/bad.py @@ -1 +1 @@ -foo = lambda x: x**2 + 2*x + 1 # [unnecessary-lambda-assignment] +foo = lambda x: x**2 + 2 * x + 1 # [unnecessary-lambda-assignment] diff --git a/doc/data/messages/u/unnecessary-lambda-assignment/good.py b/doc/data/messages/u/unnecessary-lambda-assignment/good.py index 19c0a07d5..5c7da57a0 100644 --- a/doc/data/messages/u/unnecessary-lambda-assignment/good.py +++ b/doc/data/messages/u/unnecessary-lambda-assignment/good.py @@ -1,2 +1,2 @@ def foo(x): - return x**2 + 2*x + 1 + return x**2 + 2 * x + 1 diff --git a/doc/data/messages/u/unnecessary-list-index-lookup/bad.py b/doc/data/messages/u/unnecessary-list-index-lookup/bad.py index d312d36a0..b671b3add 100644 --- a/doc/data/messages/u/unnecessary-list-index-lookup/bad.py +++ b/doc/data/messages/u/unnecessary-list-index-lookup/bad.py @@ -1,4 +1,4 @@ -letters = ['a', 'b', 'c'] +letters = ["a", "b", "c"] for index, letter in enumerate(letters): print(letters[index]) # [unnecessary-list-index-lookup] diff --git a/doc/data/messages/u/unnecessary-list-index-lookup/good.py b/doc/data/messages/u/unnecessary-list-index-lookup/good.py index 5d3370c0e..2d1a3425c 100644 --- a/doc/data/messages/u/unnecessary-list-index-lookup/good.py +++ b/doc/data/messages/u/unnecessary-list-index-lookup/good.py @@ -1,4 +1,4 @@ -letters = ['a', 'b', 'c'] +letters = ["a", "b", "c"] for index, letter in enumerate(letters): print(letter) diff --git a/doc/data/messages/u/unnecessary-pass/bad.py b/doc/data/messages/u/unnecessary-pass/bad.py index 32eee7f94..c22786f63 100644 --- a/doc/data/messages/u/unnecessary-pass/bad.py +++ b/doc/data/messages/u/unnecessary-pass/bad.py @@ -1,3 +1,4 @@ class Foo: """Foo docstring.""" + pass # [unnecessary-pass] diff --git a/doc/data/messages/u/unsupported-binary-operation/good.py b/doc/data/messages/u/unsupported-binary-operation/good.py index 8dc2893c3..6a6be9a72 100644 --- a/doc/data/messages/u/unsupported-binary-operation/good.py +++ b/doc/data/messages/u/unsupported-binary-operation/good.py @@ -1,2 +1,2 @@ masked = 0b111111 & 0b001100 -result = 0xaeff | 0x0b99 +result = 0xAEFF | 0x0B99 diff --git a/doc/data/messages/u/unsupported-membership-test/good.py b/doc/data/messages/u/unsupported-membership-test/good.py index 96b96d4d5..a5af58d5d 100644 --- a/doc/data/messages/u/unsupported-membership-test/good.py +++ b/doc/data/messages/u/unsupported-membership-test/good.py @@ -1,5 +1,6 @@ class Fruit: FRUITS = ["apple", "orange"] + def __contains__(self, name): return name in self.FRUITS diff --git a/doc/data/messages/u/unused-format-string-key/bad.py b/doc/data/messages/u/unused-format-string-key/bad.py index b4c518fc3..7a326da28 100644 --- a/doc/data/messages/u/unused-format-string-key/bad.py +++ b/doc/data/messages/u/unused-format-string-key/bad.py @@ -1,2 +1,5 @@ -"The quick %(color)s fox jumps over the lazy dog." % {"color": "brown", "action": "hops"} -# -1: [unused-format-string-key] +"The quick %(color)s fox jumps over the lazy dog." % { + "color": "brown", + "action": "hops", +} +# -4: [unused-format-string-key] diff --git a/doc/data/messages/u/unused-format-string-key/good.py b/doc/data/messages/u/unused-format-string-key/good.py index 5e45475fd..9347a3d8f 100644 --- a/doc/data/messages/u/unused-format-string-key/good.py +++ b/doc/data/messages/u/unused-format-string-key/good.py @@ -1 +1,4 @@ -"The quick %(color)s fox %(action)s over the lazy dog." % {"color": "brown", "action": "hops"} +"The quick %(color)s fox %(action)s over the lazy dog." % { + "color": "brown", + "action": "hops", +} diff --git a/doc/data/messages/u/unused-wildcard-import/bad.py b/doc/data/messages/u/unused-wildcard-import/bad.py index 8d4858161..74e052c84 100644 --- a/doc/data/messages/u/unused-wildcard-import/bad.py +++ b/doc/data/messages/u/unused-wildcard-import/bad.py @@ -1,4 +1,5 @@ from abc import * # [unused-wildcard-import] -class Animal(ABC): ... +class Animal(ABC): + ... diff --git a/doc/data/messages/u/unused-wildcard-import/good.py b/doc/data/messages/u/unused-wildcard-import/good.py index 961af9915..46fab6d4c 100644 --- a/doc/data/messages/u/unused-wildcard-import/good.py +++ b/doc/data/messages/u/unused-wildcard-import/good.py @@ -1,4 +1,5 @@ from abc import ABC -class Animal(ABC): ... +class Animal(ABC): + ... diff --git a/doc/data/messages/u/useless-parent-delegation/bad.py b/doc/data/messages/u/useless-parent-delegation/bad.py index 9010c9ea9..5132e358c 100644 --- a/doc/data/messages/u/useless-parent-delegation/bad.py +++ b/doc/data/messages/u/useless-parent-delegation/bad.py @@ -1,10 +1,8 @@ class Animal: - def eat(self, food): print(f"Eating {food}") class Human(Animal): - def eat(self, food): # [useless-parent-delegation] super(Human, self).eat(food) diff --git a/doc/data/messages/u/useless-parent-delegation/good.py b/doc/data/messages/u/useless-parent-delegation/good.py index d463b4564..890a43116 100644 --- a/doc/data/messages/u/useless-parent-delegation/good.py +++ b/doc/data/messages/u/useless-parent-delegation/good.py @@ -1,5 +1,4 @@ class Animal: - def eat(self, food): print(f"Eating {food}") diff --git a/doc/data/messages/u/using-constant-test/bad.py b/doc/data/messages/u/using-constant-test/bad.py index aee0b407c..a995d7804 100644 --- a/doc/data/messages/u/using-constant-test/bad.py +++ b/doc/data/messages/u/using-constant-test/bad.py @@ -1,4 +1,4 @@ if 0: # [using-constant-test] - print('This code is never executed.') + print("This code is never executed.") if 1: # [using-constant-test] - print('This code is always executed.') + print("This code is always executed.") diff --git a/doc/data/messages/u/using-constant-test/good.py b/doc/data/messages/u/using-constant-test/good.py index 151e1d518..c8441a924 100644 --- a/doc/data/messages/u/using-constant-test/good.py +++ b/doc/data/messages/u/using-constant-test/good.py @@ -1 +1 @@ -print('This code is always executed.') +print("This code is always executed.") diff --git a/doc/data/messages/w/while-used/bad.py b/doc/data/messages/w/while-used/bad.py index 8839b1a83..44e8df854 100644 --- a/doc/data/messages/w/while-used/bad.py +++ b/doc/data/messages/w/while-used/bad.py @@ -4,9 +4,9 @@ import requests def fetch_data(): i = 1 while i < 6: # [while-used] - print(f'Attempt {i}...') + print(f"Attempt {i}...") try: - return requests.get('https://example.com/data') + return requests.get("https://example.com/data") except requests.exceptions.RequestException: pass i += 1 diff --git a/doc/data/messages/w/while-used/good.py b/doc/data/messages/w/while-used/good.py index 3f2be4860..762d73840 100644 --- a/doc/data/messages/w/while-used/good.py +++ b/doc/data/messages/w/while-used/good.py @@ -3,8 +3,8 @@ import requests def fetch_data(): for i in range(1, 6): - print(f'Attempt {i}...') + print(f"Attempt {i}...") try: - return requests.get('https://example.com/data') + return requests.get("https://example.com/data") except requests.exceptions.RequestException: pass diff --git a/doc/data/messages/w/wrong-exception-operation/bad.py b/doc/data/messages/w/wrong-exception-operation/bad.py index 20fcc2aab..e4aff5d8b 100644 --- a/doc/data/messages/w/wrong-exception-operation/bad.py +++ b/doc/data/messages/w/wrong-exception-operation/bad.py @@ -1,4 +1,4 @@ try: - 1/0 -except (ValueError + TypeError): # [wrong-exception-operation] + 1 / 0 +except ValueError + TypeError: # [wrong-exception-operation] pass diff --git a/doc/data/messages/w/wrong-exception-operation/good.py b/doc/data/messages/w/wrong-exception-operation/good.py index 4171dbb60..b5170dd0e 100644 --- a/doc/data/messages/w/wrong-exception-operation/good.py +++ b/doc/data/messages/w/wrong-exception-operation/good.py @@ -1,4 +1,4 @@ try: - 1/0 + 1 / 0 except (ValueError, TypeError): pass diff --git a/doc/data/messages/w/wrong-import-position/bad.py b/doc/data/messages/w/wrong-import-position/bad.py index f5162adeb..38e442e97 100644 --- a/doc/data/messages/w/wrong-import-position/bad.py +++ b/doc/data/messages/w/wrong-import-position/bad.py @@ -1,7 +1,7 @@ import os -home = os.environ['HOME'] +home = os.environ["HOME"] import sys # [wrong-import-position] -print(f'Home directory is {home}', file=sys.stderr) +print(f"Home directory is {home}", file=sys.stderr) diff --git a/doc/data/messages/w/wrong-import-position/good.py b/doc/data/messages/w/wrong-import-position/good.py index 413e1944e..37330eb23 100644 --- a/doc/data/messages/w/wrong-import-position/good.py +++ b/doc/data/messages/w/wrong-import-position/good.py @@ -1,5 +1,5 @@ import os import sys -home = os.environ['HOME'] -print(f'Home directory is {home}', file=sys.stderr) +home = os.environ["HOME"] +print(f"Home directory is {home}", file=sys.stderr) -- cgit v1.2.1