SourceAnalyzer
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class SourceAnalyzer(ast.NodeVisitor):
"""AST source code analyzer.
>>> import ast
Function generic_visit
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def generic_visit(self, node):
"""Called if no explicit visitor function exists for a node
(override)."""
# Continue visiting if only if `__all__` has not overridden.
if (not self._has_all) or isinstance(node, ast.AugAssign):
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function visit_Subscript
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def visit_Subscript(self, node: ast.Subscript) -> None:
#: Support semi string type assigment
#:
#: >>> from ast import Import, ImportFrom
#: >>> from typing import Union, List
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function generic_visit
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
def generic_visit(self, node):
"""Called if no explicit visitor function exists for a node
(override)."""
# Continue visiting if only if there's no know side effects.
if self._has_side_effects is HasSideEffects.NO:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function visit_Call
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def visit_Call(self, node: ast.Call):
func = node.func
#: Support casting case.
#: >>> from typing import cast
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function expand_import_star
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def expand_import_star(
node: Union[ast.ImportFrom, _nodes.ImportFrom], path: Path
) -> Union[ast.ImportFrom, _nodes.ImportFrom]:
"""Expand import star statement, replace the `*` with a list of ast.alias.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function visit_Expr
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def visit_Expr(self, node: ast.Expr):
#: Support `__all__` dunder overriding with
#: `append` and `extend` operations:
#:
#: >>> import x, y, z
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function visit_Expr
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def visit_Expr(self, node: ast.Expr):
#: Support `__all__` dunder overriding with
#: `append` and `extend` operations:
#:
#: >>> import x, y, z
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function visit_ClassDef
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def visit_ClassDef(self, node: ast.ClassDef):
#: Support imports used in generics and wrapped in string:
#:
#: >>> from typing import Generic
#: >>> from foo import Bar
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _get_end_lineno
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
def _get_end_lineno(self, lineno: int, is_parentheses: bool) -> int:
# Get `ast.ImportFrom` `end_lineno` of the given `lineno`.
lines_len = len(self._lines)
for end_lineno in range(lineno, lines_len):
if is_parentheses:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _add_list_names
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def _add_list_names(self, node: List[ast.expr]) -> None:
# Safely add list `const/str` names to `self._importables`.
for item in node:
if isinstance(item, (ast.Constant, ast.Str)):
key = "s" if hasattr(item, "s") else "value"
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _add_list_names
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def _add_list_names(self, node: List[ast.expr]) -> None:
# Safely add list `const/str` names to `self._source_stats.name_`.
for item in node:
if isinstance(item, (ast.Constant, ast.Str)):
key = "s" if hasattr(item, "s") else "value"
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if isinstance(item, ast.AST):
self.visit(item)
elif isinstance(value, ast.AST):
Function _compute_not_importables
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def _compute_not_importables(self, node: Union[FunctionDefT, ast.ClassDef]):
# Compute class/function not-importables.
for node_ in ast.iter_child_nodes(node):
if isinstance(node_, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
self._not_importables.add(cast(str, node_.name))
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid deeply nested control flow statements. Open
if isinstance(item, ast.AST):
self.visit(item)
elif isinstance(value, ast.AST):
Function get_stats
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def get_stats(self) -> Set[str]:
if self._path.name == "__init__.py":
for path in os.listdir(self._path.parent):
file_path = self._path.parent.joinpath(path)
if file_path.is_dir() or path.endswith(".py"):
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _compute_not_side_effects
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _compute_not_side_effects(
self, node: Union[ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef]
) -> None:
# Mark any call inside the given `node` as not-side-effect.
for node_ in ast.iter_child_nodes(node):
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _parse_string
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _parse_string(
self, node: Union[ast.Constant, ast.Str], is_str_annotation: bool = False
) -> None:
try:
# Parse string names/attrs.
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _visit_type_comment
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _visit_type_comment(
self, node: Union[ast.Assign, ast.arg, FunctionDefT]
) -> None:
#: Support Python ^3.8 type comments.
#:
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function _visit_string_type_annotation
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _visit_string_type_annotation(
self, node: Union[ast.AnnAssign, ast.arg, FunctionDefT]
) -> None:
# Support string type annotations.
if isinstance(node, (ast.AnnAssign, ast.arg)):
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"