diff options
author | Nick Drozd <nicholasdrozd@gmail.com> | 2023-01-28 13:35:46 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-28 19:35:46 +0100 |
commit | af555eddf6ecdb1993345dce728a6b4c38dd4a02 (patch) | |
tree | a0c05f8d37da73c4021c82b7c9e8ce5df5aad855 | |
parent | acb28d8fcefb06179d9e6528ba14dd099e12ecfa (diff) | |
download | pylint-git-af555eddf6ecdb1993345dce728a6b4c38dd4a02.tar.gz |
Tighten design constraints (#8115)
* Lower max locals
* Lower max statements
* Lower max try statements
* Lower max branches
* Lower max args
* Cut design constraints with default values
-rw-r--r-- | pylint/checkers/base/basic_checker.py | 1 | ||||
-rw-r--r-- | pylint/checkers/classes/class_checker.py | 3 | ||||
-rw-r--r-- | pylint/checkers/format.py | 2 | ||||
-rw-r--r-- | pylint/checkers/imports.py | 1 | ||||
-rw-r--r-- | pylint/checkers/refactoring/refactoring_checker.py | 1 | ||||
-rw-r--r-- | pylint/checkers/similar.py | 1 | ||||
-rw-r--r-- | pylint/checkers/spelling.py | 1 | ||||
-rw-r--r-- | pylint/checkers/stdlib.py | 1 | ||||
-rw-r--r-- | pylint/checkers/strings.py | 3 | ||||
-rw-r--r-- | pylint/checkers/typecheck.py | 5 | ||||
-rw-r--r-- | pylint/checkers/utils.py | 4 | ||||
-rw-r--r-- | pylint/checkers/variables.py | 6 | ||||
-rw-r--r-- | pylint/lint/expand_modules.py | 1 | ||||
-rw-r--r-- | pylint/lint/run.py | 1 | ||||
-rw-r--r-- | pylint/testutils/output_line.py | 1 | ||||
-rw-r--r-- | pylint/utils/ast_walker.py | 1 | ||||
-rw-r--r-- | pylintrc | 29 | ||||
-rw-r--r-- | tests/checkers/unittest_deprecated.py | 1 | ||||
-rw-r--r-- | tests/checkers/unittest_format.py | 1 | ||||
-rw-r--r-- | tests/lint/unittest_lint.py | 1 | ||||
-rw-r--r-- | tests/test_self.py | 1 |
21 files changed, 37 insertions, 29 deletions
diff --git a/pylint/checkers/base/basic_checker.py b/pylint/checkers/base/basic_checker.py index 01caa0770..fcc980d22 100644 --- a/pylint/checkers/base/basic_checker.py +++ b/pylint/checkers/base/basic_checker.py @@ -104,6 +104,7 @@ def report_by_type_stats( sect.append(reporter_nodes.Table(children=lines, cols=6, rheaders=1)) +# pylint: disable-next = too-many-public-methods class BasicChecker(_BasicChecker): """Basic checker. diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index 25fc0014d..cf2fc39e2 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -1150,6 +1150,7 @@ a metaclass class method.", "attribute-defined-outside-init", args=attr, node=node ) + # pylint: disable = too-many-branches def visit_functiondef(self, node: nodes.FunctionDef) -> None: """Check method arguments, overriding.""" # ignore actual functions @@ -1218,6 +1219,7 @@ a metaclass class method.", pass # check if the method is hidden by an attribute + # pylint: disable = too-many-try-statements try: overridden = klass.instance_attr(node.name)[0] overridden_frame = overridden.frame(future=True) @@ -2063,6 +2065,7 @@ a metaclass class method.", and expr.expr.func.name == "super" ): return + # pylint: disable = too-many-try-statements try: for klass in expr.expr.infer(): if klass is astroid.Uninferable: diff --git a/pylint/checkers/format.py b/pylint/checkers/format.py index 001330b2b..562c48f5d 100644 --- a/pylint/checkers/format.py +++ b/pylint/checkers/format.py @@ -275,7 +275,7 @@ class FormatChecker(BaseTokenChecker, BaseRawFileChecker): def process_module(self, node: nodes.Module) -> None: pass - # pylint: disable-next=too-many-return-statements + # pylint: disable-next = too-many-return-statements, too-many-branches def _check_keyword_parentheses( self, tokens: list[tokenize.TokenInfo], start: int ) -> None: diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py index 653bd85c9..a66400441 100644 --- a/pylint/checkers/imports.py +++ b/pylint/checkers/imports.py @@ -737,6 +737,7 @@ class ImportsChecker(DeprecatedMixin, BaseChecker): imports = [import_node for (import_node, _) in imports] return any(astroid.are_exclusive(import_node, node) for import_node in imports) + # pylint: disable = too-many-statements def _check_imports_order( self, _module_node: nodes.Module ) -> tuple[ diff --git a/pylint/checkers/refactoring/refactoring_checker.py b/pylint/checkers/refactoring/refactoring_checker.py index f6db3419f..0d51784ae 100644 --- a/pylint/checkers/refactoring/refactoring_checker.py +++ b/pylint/checkers/refactoring/refactoring_checker.py @@ -854,6 +854,7 @@ class RefactoringChecker(checkers.BaseTokenChecker): self._check_consider_get(node) self._check_consider_using_min_max_builtin(node) + # pylint: disable = too-many-branches def _check_consider_using_min_max_builtin(self, node: nodes.If) -> None: """Check if the given if node can be refactored as a min/max python builtin.""" if self._is_actual_elif(node) or node.orelse: diff --git a/pylint/checkers/similar.py b/pylint/checkers/similar.py index 69b0677bd..bc485a981 100644 --- a/pylint/checkers/similar.py +++ b/pylint/checkers/similar.py @@ -474,6 +474,7 @@ class Similar: ) return report + # pylint: disable = too-many-locals def _find_common( self, lineset1: LineSet, lineset2: LineSet ) -> Generator[Commonality, None, None]: diff --git a/pylint/checkers/spelling.py b/pylint/checkers/spelling.py index 7b0db655f..61229ddca 100644 --- a/pylint/checkers/spelling.py +++ b/pylint/checkers/spelling.py @@ -340,6 +340,7 @@ class SpellingChecker(BaseTokenChecker): ) self.initialized = True + # pylint: disable = too-many-statements def _check_spelling(self, msgid: str, line: str, line_num: int) -> None: original_line = line try: diff --git a/pylint/checkers/stdlib.py b/pylint/checkers/stdlib.py index 88a61a119..c9bec3823 100644 --- a/pylint/checkers/stdlib.py +++ b/pylint/checkers/stdlib.py @@ -605,6 +605,7 @@ class StdlibChecker(DeprecatedMixin, BaseChecker): lru_cache_nodes: list[nodes.NodeNG] = [] for d_node in node.decorators.nodes: + # pylint: disable = too-many-try-statements try: for infered_node in d_node.infer(): q_name = infered_node.qname() diff --git a/pylint/checkers/strings.py b/pylint/checkers/strings.py index 4afe32a16..d5be5aa53 100644 --- a/pylint/checkers/strings.py +++ b/pylint/checkers/strings.py @@ -247,7 +247,7 @@ class StringFormatChecker(BaseChecker): name = "string" msgs = MSGS - # pylint: disable=too-many-branches + # pylint: disable = too-many-branches, too-many-locals, too-many-statements @only_required_for_messages( "bad-format-character", "truncated-format-string", @@ -533,6 +533,7 @@ class StringFormatChecker(BaseChecker): self._detect_vacuous_formatting(node, positional_arguments) self._check_new_format_specifiers(node, fields, named_arguments) + # pylint: disable = too-many-statements def _check_new_format_specifiers( self, node: nodes.Call, diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index c19056284..bfd415923 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -440,7 +440,7 @@ def _emit_no_member( AttributeError, Exception or bare except. * The node is guarded behind and `IF` or `IFExp` node """ - # pylint: disable=too-many-return-statements + # pylint: disable = too-many-return-statements, too-many-branches if node_ignores_exception(node, AttributeError): return False if ignored_none and isinstance(owner, nodes.Const) and owner.value is None: @@ -1035,6 +1035,7 @@ accessed. Python regular expressions are accepted.", def visit_delattr(self, node: nodes.DelAttr) -> None: self.visit_attribute(node) + # pylint: disable = too-many-branches @only_required_for_messages("no-member", "c-extension-no-member") def visit_attribute( self, node: nodes.Attribute | nodes.AssignAttr | nodes.DelAttr @@ -1399,7 +1400,7 @@ accessed. Python regular expressions are accepted.", if _is_invalid_isinstance_type(second_arg): self.add_message("isinstance-second-argument-not-valid-type", node=node) - # pylint: disable=too-many-branches,too-many-locals + # pylint: disable = too-many-branches, too-many-locals, too-many-statements def visit_call(self, node: nodes.Call) -> None: """Check that called functions/methods are inferred to callable objects, and that passed arguments match the parameters in the inferred function. diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index 337e34ad6..52ef2d274 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -303,6 +303,7 @@ def is_defined_in_scope( return defnode_in_scope(var_node, varname, scope) is not None +# pylint: disable = too-many-branches def defnode_in_scope( var_node: nodes.NodeNG, varname: str, @@ -627,6 +628,7 @@ def collect_string_fields(format_string: str) -> Iterable[str | None]: It handles nested fields as well. """ formatter = string.Formatter() + # pylint: disable = too-many-try-statements try: parseiterator = formatter.parse(format_string) for result in parseiterator: @@ -1374,6 +1376,7 @@ def safe_infer( if value is not astroid.Uninferable: inferred_types.add(_get_python_type_of_node(value)) + # pylint: disable = too-many-try-statements try: for inferred in infer_gen: inferred_type = _get_python_type_of_node(inferred) @@ -2050,6 +2053,7 @@ def is_hashable(node: nodes.NodeNG) -> bool: When finding ambiguity, return True. """ + # pylint: disable = too-many-try-statements try: for inferred in node.infer(): if inferred is astroid.Uninferable or isinstance(inferred, nodes.ClassDef): diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 0019cec7a..583f41094 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -1661,7 +1661,7 @@ class VariablesChecker(BaseChecker): return False - # pylint: disable=too-many-return-statements + # pylint: disable = too-many-return-statements, too-many-branches def _check_consumer( self, node: nodes.Name, @@ -2025,6 +2025,7 @@ class VariablesChecker(BaseChecker): parent = parent.parent return False + # pylint: disable = too-many-statements, too-many-branches @staticmethod def _is_variable_violation( node: nodes.Name, @@ -2402,6 +2403,7 @@ class VariablesChecker(BaseChecker): and name in frame_locals ) + # pylint: disable = too-many-branches def _loopvar_name(self, node: astroid.Name) -> None: # filter variables according to node's scope astmts = [s for s in node.lookup(node.name)[1] if hasattr(s, "assign_type")] @@ -2546,6 +2548,7 @@ class VariablesChecker(BaseChecker): if not elements: self.add_message("undefined-loop-variable", args=node.name, node=node) + # pylint: disable = too-many-branches def _check_is_unused( self, name: str, @@ -3011,6 +3014,7 @@ class VariablesChecker(BaseChecker): for node in node_lst: self.add_message("unused-variable", args=(name,), node=node) + # pylint: disable = too-many-branches def _check_imports(self, not_consumed: dict[str, list[nodes.NodeNG]]) -> None: local_names = _fix_dot_imports(not_consumed) checked = set() diff --git a/pylint/lint/expand_modules.py b/pylint/lint/expand_modules.py index e43208dea..8259e25ad 100644 --- a/pylint/lint/expand_modules.py +++ b/pylint/lint/expand_modules.py @@ -61,6 +61,7 @@ def _is_ignored_file( ) +# pylint: disable = too-many-locals, too-many-statements def expand_modules( files_or_modules: Sequence[str], ignore_list: list[str], diff --git a/pylint/lint/run.py b/pylint/lint/run.py index 1f54670ef..a753f7868 100644 --- a/pylint/lint/run.py +++ b/pylint/lint/run.py @@ -115,6 +115,7 @@ group are mutually exclusive.", Used by _PylintConfigRun to make the 'pylint-config' command work. """ + # pylint: disable = too-many-statements, too-many-branches def __init__( self, args: Sequence[str], diff --git a/pylint/testutils/output_line.py b/pylint/testutils/output_line.py index a2c417621..7465fce9d 100644 --- a/pylint/testutils/output_line.py +++ b/pylint/testutils/output_line.py @@ -90,6 +90,7 @@ class OutputLine(NamedTuple): if isinstance(row, str): row = row.split(",") # noinspection PyBroadException + # pylint: disable = too-many-try-statements try: column = cls._get_column(row[2]) if len(row) == 5: diff --git a/pylint/utils/ast_walker.py b/pylint/utils/ast_walker.py index 4d552d995..cf0f13fd1 100644 --- a/pylint/utils/ast_walker.py +++ b/pylint/utils/ast_walker.py @@ -82,6 +82,7 @@ class ASTWalker: visit_events: Sequence[AstCallback] = self.visit_events.get(cid, ()) leave_events: Sequence[AstCallback] = self.leave_events.get(cid, ()) + # pylint: disable = too-many-try-statements try: if astroid.is_statement: self.nbstatements += 1 @@ -411,44 +411,25 @@ max-spelling-suggestions=2 [DESIGN] # Maximum number of arguments for function / method -max-args=10 +max-args = 9 # Maximum number of locals for function / method body -max-locals=25 +max-locals = 19 # Maximum number of return / yield for function / method body max-returns=11 # Maximum number of branch for function / method body -max-branches=27 +max-branches = 20 # Maximum number of statements in function / method body -max-statements=100 - -# Maximum number of parents for a class (see R0901). -max-parents=7 - -# List of qualified class names to ignore when counting class parents (see R0901). -ignored-parents= +max-statements = 50 # Maximum number of attributes for a class (see R0902). max-attributes=11 -# Minimum number of public methods for a class (see R0903). -min-public-methods=2 - -# Maximum number of public methods for a class (see R0904). -max-public-methods=25 - -# Maximum number of boolean expressions in an if statement (see R0916). -max-bool-expr=5 - # Maximum number of statements in a try-block -max-try-statements = 14 - -# List of regular expressions of class ancestor names to -# ignore when counting public methods (see R0903). -exclude-too-few-public-methods= +max-try-statements = 7 [CLASSES] diff --git a/tests/checkers/unittest_deprecated.py b/tests/checkers/unittest_deprecated.py index b02992e99..d34150247 100644 --- a/tests/checkers/unittest_deprecated.py +++ b/tests/checkers/unittest_deprecated.py @@ -53,6 +53,7 @@ class _DeprecatedChecker(DeprecatedMixin, BaseChecker): return {".deprecated_decorator"} +# pylint: disable-next = too-many-public-methods class TestDeprecatedChecker(CheckerTestCase): CHECKER_CLASS = _DeprecatedChecker diff --git a/tests/checkers/unittest_format.py b/tests/checkers/unittest_format.py index 9a34429ee..fd0699daa 100644 --- a/tests/checkers/unittest_format.py +++ b/tests/checkers/unittest_format.py @@ -165,6 +165,7 @@ def test_disable_global_option_end_of_line() -> None: 1 """ ) + # pylint: disable = too-many-try-statements try: linter = lint.PyLinter() checker = BasicChecker(linter) diff --git a/tests/lint/unittest_lint.py b/tests/lint/unittest_lint.py index 8e117f363..619c5fe12 100644 --- a/tests/lint/unittest_lint.py +++ b/tests/lint/unittest_lint.py @@ -979,6 +979,7 @@ def test_pylintrc() -> None: with fake_home(): current_dir = getcwd() chdir(os.path.dirname(os.path.abspath(sys.executable))) + # pylint: disable = too-many-try-statements try: with pytest.warns(DeprecationWarning): assert config.find_pylintrc() is None diff --git a/tests/test_self.py b/tests/test_self.py index 076f2a22f..ca7b0b6c3 100644 --- a/tests/test_self.py +++ b/tests/test_self.py @@ -781,6 +781,7 @@ a.py:1:4: E0001: Parsing failed: 'invalid syntax (<unknown>, line 1)' (syntax-er @staticmethod def test_modify_sys_path() -> None: + # pylint: disable = too-many-statements cwd = "/tmp/pytest-of-root/pytest-0/test_do_not_import_files_from_0" default_paths = [ "/usr/local/lib/python39.zip", |