summaryrefslogtreecommitdiff
path: root/pylint/checkers/design_analysis.py
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-09-03 13:47:23 +0200
committerGitHub <noreply@github.com>2021-09-03 13:47:23 +0200
commitbaaa81a2994cdd517fbde8693b0a4b0a67f5a4e3 (patch)
treec8b26e345fb3c7377a6c8e3a2b7afca28e1806e5 /pylint/checkers/design_analysis.py
parent0981d8bec52f0917168e0e89947fe164f58be683 (diff)
downloadpylint-git-baaa81a2994cdd517fbde8693b0a4b0a67f5a4e3.tar.gz
Refactor various typing related issues (#4940)
* Add type annotations to ``visit`` & ``leave`` calls This adds typing to most calls that visit nodes. All other changes are due to mypy errors resulting from introduction of typing. * Fix outstanding mypy issues This removes some of the `type: ignore` comments in favour of solving the mypy issues these comments were surpressing. * Fix remaining references to node_classes Except for two references to node_classes in the changelog this should be the last of them Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'pylint/checkers/design_analysis.py')
-rw-r--r--pylint/checkers/design_analysis.py22
1 files changed, 11 insertions, 11 deletions
diff --git a/pylint/checkers/design_analysis.py b/pylint/checkers/design_analysis.py
index dbc132be4..9777b568e 100644
--- a/pylint/checkers/design_analysis.py
+++ b/pylint/checkers/design_analysis.py
@@ -264,7 +264,7 @@ def _get_parents(
if parent.qname() in ignored_parents:
continue
parents.add(parent)
- to_explore.extend(parent.ancestors(recurs=False)) # type: ignore
+ to_explore.extend(parent.ancestors(recurs=False))
return parents
@@ -417,7 +417,7 @@ class MisdesignChecker(BaseChecker):
"too-few-public-methods",
"too-many-public-methods",
)
- def visit_classdef(self, node: nodes.ClassDef):
+ def visit_classdef(self, node: nodes.ClassDef) -> None:
"""check size of inheritance hierarchy and number of instance attributes"""
parents = _get_parents(
node, STDLIB_CLASSES_IGNORE_ANCESTOR.union(self.config.ignored_parents)
@@ -438,7 +438,7 @@ class MisdesignChecker(BaseChecker):
)
@check_messages("too-few-public-methods", "too-many-public-methods")
- def leave_classdef(self, node):
+ def leave_classdef(self, node: nodes.ClassDef) -> None:
"""check number of public methods"""
my_methods = sum(
1 for method in node.mymethods() if not method.name.startswith("_")
@@ -482,7 +482,7 @@ class MisdesignChecker(BaseChecker):
"too-many-statements",
"keyword-arg-before-vararg",
)
- def visit_functiondef(self, node):
+ def visit_functiondef(self, node: nodes.FunctionDef) -> None:
"""check function name, docstring, arguments, redefinition,
variable names, max locals
"""
@@ -525,7 +525,7 @@ class MisdesignChecker(BaseChecker):
"too-many-locals",
"too-many-statements",
)
- def leave_functiondef(self, node):
+ def leave_functiondef(self, node: nodes.FunctionDef) -> None:
"""most of the work is done here on close:
checks for max returns, branch, return in __init__
"""
@@ -554,20 +554,20 @@ class MisdesignChecker(BaseChecker):
leave_asyncfunctiondef = leave_functiondef
- def visit_return(self, _):
+ def visit_return(self, _: nodes.Return) -> None:
"""count number of returns"""
if not self._returns:
return # return outside function, reported by the base checker
self._returns[-1] += 1
- def visit_default(self, node):
+ def visit_default(self, node: nodes.NodeNG) -> None:
"""default visit method -> increments the statements counter if
necessary
"""
if node.is_statement:
self._inc_all_stmts(1)
- def visit_tryexcept(self, node):
+ def visit_tryexcept(self, node: nodes.TryExcept) -> None:
"""increments the branches counter"""
branches = len(node.handlers)
if node.orelse:
@@ -575,13 +575,13 @@ class MisdesignChecker(BaseChecker):
self._inc_branch(node, branches)
self._inc_all_stmts(branches)
- def visit_tryfinally(self, node):
+ def visit_tryfinally(self, node: nodes.TryFinally) -> None:
"""increments the branches counter"""
self._inc_branch(node, 2)
self._inc_all_stmts(2)
@check_messages("too-many-boolean-expressions")
- def visit_if(self, node):
+ def visit_if(self, node: nodes.If) -> None:
"""increments the branches counter and checks boolean expressions"""
self._check_boolean_expressions(node)
branches = 1
@@ -609,7 +609,7 @@ class MisdesignChecker(BaseChecker):
args=(nb_bool_expr, self.config.max_bool_expr),
)
- def visit_while(self, node):
+ def visit_while(self, node: nodes.While) -> None:
"""increments the branches counter"""
branches = 1
if node.orelse: