diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7ea6c53430..9689d319e9 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -44,7 +44,7 @@ repos: - id: isort exclude: doc/data/messages/(r/reimported|w/wrong-import-order|u/ungrouped-imports|m/misplaced-future|m/multiple-imports)/bad.py - repo: https://github.com/psf/black - rev: 22.12.0 + rev: 23.1a1 hooks: - id: black args: [--safe, --quiet] diff --git a/examples/custom_raw.py b/examples/custom_raw.py index 1cfeae3f9c..090f87ea8f 100644 --- a/examples/custom_raw.py +++ b/examples/custom_raw.py @@ -32,7 +32,7 @@ def process_module(self, node: nodes.Module) -> None: the module's content is accessible via node.stream() function """ with node.stream() as stream: - for (lineno, line) in enumerate(stream): + for lineno, line in enumerate(stream): if line.rstrip().endswith("\\"): self.add_message("backslash-line-continuation", line=lineno) diff --git a/pylint/checkers/base/basic_error_checker.py b/pylint/checkers/base/basic_error_checker.py index f76c5aa8b6..e1936ef37f 100644 --- a/pylint/checkers/base/basic_error_checker.py +++ b/pylint/checkers/base/basic_error_checker.py @@ -301,7 +301,6 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None: visit_asyncfunctiondef = visit_functiondef def _check_name_used_prior_global(self, node: nodes.FunctionDef) -> None: - scope_globals = { name: child for child in node.nodes_of_class(nodes.Global) diff --git a/pylint/checkers/base_checker.py b/pylint/checkers/base_checker.py index 0debfd3a2a..f44bf032aa 100644 --- a/pylint/checkers/base_checker.py +++ b/pylint/checkers/base_checker.py @@ -34,7 +34,6 @@ @functools.total_ordering class BaseChecker(_ArgumentsProvider): - # checker name (you may reuse an existing one) name: str = "" # ordered list of options to control the checker behaviour diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index 281eed15f5..437dae4c52 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -975,7 +975,6 @@ def _check_unused_private_functions(self, node: nodes.ClassDef) -> None: "cls", node.name, }: - break # Check type(self).__attrname diff --git a/pylint/checkers/classes/special_methods_checker.py b/pylint/checkers/classes/special_methods_checker.py index 6d95615b14..b57ec641c9 100644 --- a/pylint/checkers/classes/special_methods_checker.py +++ b/pylint/checkers/classes/special_methods_checker.py @@ -394,7 +394,6 @@ def _check_getnewargs_ex( (inferred.elts[0], self._is_tuple), (inferred.elts[1], self._is_dict), ): - if isinstance(arg, nodes.Call): arg = safe_infer(arg) diff --git a/pylint/checkers/misc.py b/pylint/checkers/misc.py index b48d302d8c..8f64957358 100644 --- a/pylint/checkers/misc.py +++ b/pylint/checkers/misc.py @@ -42,7 +42,7 @@ def _get_by_id_managed_msgs(self) -> list[ManagedMessage]: def process_module(self, node: nodes.Module) -> None: """Inspect the source file to find messages activated or deactivated by id.""" managed_msgs = self._get_by_id_managed_msgs() - for (mod_name, msgid, symbol, lineno, is_disabled) in managed_msgs: + for mod_name, msgid, symbol, lineno, is_disabled in managed_msgs: if mod_name == node.name: verb = "disable" if is_disabled else "enable" txt = f"'{msgid}' is cryptic: use '# pylint: {verb}={symbol}' instead" diff --git a/pylint/checkers/refactoring/recommendation_checker.py b/pylint/checkers/refactoring/recommendation_checker.py index cda26e0649..32986c268b 100644 --- a/pylint/checkers/refactoring/recommendation_checker.py +++ b/pylint/checkers/refactoring/recommendation_checker.py @@ -13,7 +13,6 @@ class RecommendationChecker(checkers.BaseChecker): - name = "refactoring" msgs = { "C0200": ( diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py index 3612385921..d9b91563ce 100644 --- a/pylint/checkers/refactoring/refactoring_checker.py +++ b/pylint/checkers/refactoring/refactoring_checker.py @@ -787,7 +787,6 @@ def _type_and_name_are_equal(node_a: Any, node_b: Any) -> bool: return False def _is_dict_get_block(self, node: nodes.If) -> bool: - # "if " if not isinstance(node.test, nodes.Compare): return False @@ -1114,7 +1113,6 @@ def _has_exit_in_scope(scope: nodes.LocalsDictNodeNG) -> bool: ) def _check_quit_exit_call(self, node: nodes.Call) -> None: - if isinstance(node.func, nodes.Name) and node.func.name in BUILTIN_EXIT_FUNCS: # If we have `exit` imported from `sys` in the current or global scope, exempt this instance. local_scope = node.scope() diff --git a/pylint/checkers/spelling.py b/pylint/checkers/spelling.py index 23209a2bc4..7b0db655f9 100644 --- a/pylint/checkers/spelling.py +++ b/pylint/checkers/spelling.py @@ -427,7 +427,7 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None: return # Process tokens and look for comments. - for (tok_type, token, (start_row, _), _, _) in tokens: + for tok_type, token, (start_row, _), _, _ in tokens: if tok_type == tokenize.COMMENT: if start_row == 1 and token.startswith("#!/"): # Skip shebang lines diff --git a/pylint/checkers/threading_checker.py b/pylint/checkers/threading_checker.py index 308b6ca26d..df0dfe7cf2 100644 --- a/pylint/checkers/threading_checker.py +++ b/pylint/checkers/threading_checker.py @@ -44,7 +44,6 @@ class ThreadingChecker(BaseChecker): @only_required_for_messages("useless-with-lock") def visit_with(self, node: nodes.With) -> None: - context_managers = (c for c, _ in node.items if isinstance(c, nodes.Call)) for context_manager in context_managers: if isinstance(context_manager, nodes.Call): diff --git a/pylint/checkers/unicode.py b/pylint/checkers/unicode.py index 35a0cd7fce..6d7b253954 100644 --- a/pylint/checkers/unicode.py +++ b/pylint/checkers/unicode.py @@ -524,7 +524,7 @@ def process_module(self, node: nodes.Module) -> None: stream.seek(0) # Check for invalid content (controls/chars) - for (lineno, line) in enumerate( + for lineno, line in enumerate( _fix_utf16_32_line_stream(stream, codec), start=1 ): if lineno == 1: diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 29911c4717..2feea3e9fb 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -1767,7 +1767,6 @@ def _check_consumer( and not utils.is_defined_before(node) and not astroid.are_exclusive(stmt, defstmt, ("NameError",)) ): - # Used and defined in the same place, e.g `x += 1` and `del x` defined_by_stmt = defstmt is stmt and isinstance( node, (nodes.DelName, nodes.AssignName) @@ -1779,7 +1778,6 @@ def _check_consumer( or isinstance(defstmt, nodes.Delete) ): if not utils.node_ignores_exception(node, NameError): - # Handle postponed evaluation of annotations if not ( self._postponed_evaluation_enabled @@ -2074,7 +2072,6 @@ def _is_variable_violation( and isinstance(frame, nodes.ClassDef) and node.name in frame.locals ): - # This rule verifies that if the definition node of the # checked name is an Arguments node and if the name # is used a default value in the arguments defaults diff --git a/pylint/epylint.py b/pylint/epylint.py index a69ce0d877..dd23b450be 100755 --- a/pylint/epylint.py +++ b/pylint/epylint.py @@ -107,7 +107,6 @@ def lint(filename: str, options: Sequence[str] = ()) -> int: with Popen( cmd, stdout=PIPE, cwd=parent_path, env=_get_env(), universal_newlines=True ) as process: - for line in process.stdout: # type: ignore[union-attr] # remove pylintrc warning if line.startswith("No config file found"): diff --git a/pylint/extensions/bad_builtin.py b/pylint/extensions/bad_builtin.py index dd6ab38418..904b2a3943 100644 --- a/pylint/extensions/bad_builtin.py +++ b/pylint/extensions/bad_builtin.py @@ -23,7 +23,6 @@ class BadBuiltinChecker(BaseChecker): - name = "deprecated_builtins" msgs = { "W0141": ( diff --git a/pylint/extensions/code_style.py b/pylint/extensions/code_style.py index 24eb7f6678..262a7f0c4d 100644 --- a/pylint/extensions/code_style.py +++ b/pylint/extensions/code_style.py @@ -225,7 +225,6 @@ def _check_consider_using_assignment_expr(self, node: nodes.If) -> None: if CodeStyleChecker._check_prev_sibling_to_if_stmt( prev_sibling, node_name.name ): - # Check if match statement would be a better fit. # I.e. multiple ifs that test the same name. if CodeStyleChecker._check_ignore_assignment_expr_suggestion( diff --git a/pylint/extensions/consider_ternary_expression.py b/pylint/extensions/consider_ternary_expression.py index c549b550ff..0e9444662a 100644 --- a/pylint/extensions/consider_ternary_expression.py +++ b/pylint/extensions/consider_ternary_expression.py @@ -17,7 +17,6 @@ class ConsiderTernaryExpressionChecker(BaseChecker): - name = "consider_ternary_expression" msgs = { "W0160": ( @@ -41,7 +40,7 @@ def visit_if(self, node: nodes.If) -> None: if not isinstance(bst, nodes.Assign) or not isinstance(ost, nodes.Assign): return - for (bname, oname) in zip(bst.targets, ost.targets): + for bname, oname in zip(bst.targets, ost.targets): if not isinstance(bname, nodes.AssignName) or not isinstance( oname, nodes.AssignName ): diff --git a/pylint/extensions/empty_comment.py b/pylint/extensions/empty_comment.py index 8685cb7e9c..e8a914708d 100644 --- a/pylint/extensions/empty_comment.py +++ b/pylint/extensions/empty_comment.py @@ -40,7 +40,6 @@ def comment_part_of_string(line: bytes, comment_idx: int) -> bool: class CommentChecker(BaseRawFileChecker): - name = "empty-comment" msgs = { "R2044": ( @@ -55,7 +54,7 @@ class CommentChecker(BaseRawFileChecker): def process_module(self, node: nodes.Module) -> None: with node.stream() as stream: - for (line_num, line) in enumerate(stream): + for line_num, line in enumerate(stream): line = line.rstrip() if line.endswith(b"#"): if not is_line_commented(line[:-1]): diff --git a/pylint/extensions/eq_without_hash.py b/pylint/extensions/eq_without_hash.py index bce2087bcd..b0d0f01bd0 100644 --- a/pylint/extensions/eq_without_hash.py +++ b/pylint/extensions/eq_without_hash.py @@ -17,7 +17,6 @@ class EqWithoutHash(checkers.BaseChecker): - name = "eq-without-hash" msgs = { diff --git a/pylint/extensions/for_any_all.py b/pylint/extensions/for_any_all.py index 257b5d37f8..bc7dd9c488 100644 --- a/pylint/extensions/for_any_all.py +++ b/pylint/extensions/for_any_all.py @@ -23,7 +23,6 @@ class ConsiderUsingAnyOrAllChecker(BaseChecker): - name = "consider-using-any-or-all" msgs = { "C0501": ( diff --git a/pylint/extensions/no_self_use.py b/pylint/extensions/no_self_use.py index 4a20873c84..0fd38877fc 100644 --- a/pylint/extensions/no_self_use.py +++ b/pylint/extensions/no_self_use.py @@ -23,7 +23,6 @@ class NoSelfUseChecker(BaseChecker): - name = "no_self_use" msgs = { "R6301": ( diff --git a/pylint/extensions/private_import.py b/pylint/extensions/private_import.py index 61d37af37f..fb4458e54d 100644 --- a/pylint/extensions/private_import.py +++ b/pylint/extensions/private_import.py @@ -19,7 +19,6 @@ class PrivateImportChecker(BaseChecker): - name = "import-private-name" msgs = { "C2701": ( diff --git a/pylint/extensions/redefined_loop_name.py b/pylint/extensions/redefined_loop_name.py index e6308cb114..df333fab9b 100644 --- a/pylint/extensions/redefined_loop_name.py +++ b/pylint/extensions/redefined_loop_name.py @@ -15,7 +15,6 @@ class RedefinedLoopNameChecker(checkers.BaseChecker): - name = "redefined-loop-name" msgs = { diff --git a/pylint/extensions/set_membership.py b/pylint/extensions/set_membership.py index d04ba9ae77..f267e046ff 100644 --- a/pylint/extensions/set_membership.py +++ b/pylint/extensions/set_membership.py @@ -16,7 +16,6 @@ class SetMembershipChecker(BaseChecker): - name = "set_membership" msgs = { "R6201": ( diff --git a/pylint/extensions/while_used.py b/pylint/extensions/while_used.py index a65092df0f..3d7a17ffe0 100644 --- a/pylint/extensions/while_used.py +++ b/pylint/extensions/while_used.py @@ -18,7 +18,6 @@ class WhileChecker(BaseChecker): - name = "while_used" msgs = { "W0149": ( diff --git a/pylint/lint/message_state_handler.py b/pylint/lint/message_state_handler.py index 7c81c2c862..ddeeaa7bca 100644 --- a/pylint/lint/message_state_handler.py +++ b/pylint/lint/message_state_handler.py @@ -347,7 +347,7 @@ def process_tokens(self, tokens: list[tokenize.TokenInfo]) -> None: prev_line = None saw_newline = True seen_newline = True - for (tok_type, content, start, _, _) in tokens: + for tok_type, content, start, _, _ in tokens: if prev_line and prev_line != start[0]: saw_newline = seen_newline seen_newline = False diff --git a/pylint/pyreverse/diagrams.py b/pylint/pyreverse/diagrams.py index 382d76bf7e..c3bf8e0f01 100644 --- a/pylint/pyreverse/diagrams.py +++ b/pylint/pyreverse/diagrams.py @@ -225,7 +225,6 @@ def extract_relationships(self) -> None: for name, values in list(node.associations_type.items()) + list( node.locals_type.items() ): - for value in values: self.assign_association_relationship( value, obj, name, "association" diff --git a/requirements_test_pre_commit.txt b/requirements_test_pre_commit.txt index 7d1daaf13c..ec1ca6bb7f 100644 --- a/requirements_test_pre_commit.txt +++ b/requirements_test_pre_commit.txt @@ -1,7 +1,7 @@ # Everything in this file should reflect the pre-commit configuration # in .pre-commit-config.yaml bandit==1.7.4 -black==22.12.0 +black==23.1a1 flake8>=5.0.0 flake8-bugbear==22.12.6 flake8-typing-imports==1.14.0 diff --git a/tests/checkers/unittest_deprecated.py b/tests/checkers/unittest_deprecated.py index a63ebfc206..b02992e998 100644 --- a/tests/checkers/unittest_deprecated.py +++ b/tests/checkers/unittest_deprecated.py @@ -25,7 +25,7 @@ def deprecated_classes(self, module: str) -> list[str]: def deprecated_arguments( self, method: str - ) -> (tuple[tuple[int | None, str], ...] | tuple[tuple[int, str], tuple[int, str]]): + ) -> tuple[tuple[int | None, str], ...] | tuple[tuple[int, str], tuple[int, str]]: if method == "myfunction1": # def myfunction1(arg1, deprecated_arg1='spam') return ((1, "deprecated_arg1"),) @@ -485,7 +485,6 @@ def mymethod2(self, arg1, deprecated_arg1, arg2='foo', deprecated_arg2='spam'): self.checker.visit_call(node) def test_class_deprecated_arguments(self) -> None: - node = astroid.extract_node( """ class MyClass: diff --git a/tests/checkers/unittest_design.py b/tests/checkers/unittest_design.py index e81a68a92e..f2ea09d2d2 100644 --- a/tests/checkers/unittest_design.py +++ b/tests/checkers/unittest_design.py @@ -9,7 +9,6 @@ class TestDesignChecker(CheckerTestCase): - CHECKER_CLASS = design_analysis.MisdesignChecker @set_config( diff --git a/tests/checkers/unittest_imports.py b/tests/checkers/unittest_imports.py index a233544429..8be4d63ffc 100644 --- a/tests/checkers/unittest_imports.py +++ b/tests/checkers/unittest_imports.py @@ -18,7 +18,6 @@ class TestImportsChecker(CheckerTestCase): - CHECKER_CLASS = imports.ImportsChecker def test_relative_beyond_top_level(self) -> None: diff --git a/tests/checkers/unittest_variables.py b/tests/checkers/unittest_variables.py index d810163d2d..e3f0132269 100644 --- a/tests/checkers/unittest_variables.py +++ b/tests/checkers/unittest_variables.py @@ -18,7 +18,6 @@ class TestVariablesChecker(CheckerTestCase): - CHECKER_CLASS = variables.VariablesChecker def test_all_elements_without_parent(self) -> None: @@ -31,7 +30,6 @@ def test_all_elements_without_parent(self) -> None: class TestVariablesCheckerWithTearDown(CheckerTestCase): - CHECKER_CLASS = variables.VariablesChecker def setup_method(self) -> None: @@ -209,7 +207,6 @@ class TestMissingSubmodule(CheckerTestCase): @staticmethod def test_package_all() -> None: - sys.path.insert(0, REGR_DATA_DIR) try: linter.check([os.path.join(REGR_DATA_DIR, "package_all")]) diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 25df951df4..8e117f363a 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -996,7 +996,6 @@ def test_pylintrc() -> None: @pytest.mark.usefixtures("pop_pylintrc") def test_pylintrc_parentdir() -> None: with tempdir() as chroot: - create_files( [ "a/pylintrc", @@ -1134,7 +1133,6 @@ def test_by_module_statement_value(initialized_linter: PyLinter) -> None: by_module_stats = linter.stats.by_module for module, module_stats in by_module_stats.items(): - linter2 = initialized_linter if module == "data": linter2.check([os.path.join(os.path.dirname(__file__), "data/__init__.py")]) diff --git a/tests/test_deprecation.py b/tests/test_deprecation.py index 1c1d132a8a..d30e69b85d 100644 --- a/tests/test_deprecation.py +++ b/tests/test_deprecation.py @@ -47,7 +47,6 @@ def test_reporter_implements() -> None: """Test that __implements__ on BaseReporter has been deprecated correctly.""" class MyReporter(BaseReporter): - __implements__ = IReporter def _display(self, layout: Section) -> None: @@ -61,7 +60,6 @@ def test_checker_implements() -> None: """Test that __implements__ on BaseChecker has been deprecated correctly.""" class MyChecker(BaseChecker): - __implements__ = IAstroidChecker with pytest.warns(DeprecationWarning):