File _transformer.py
has 981 lines of code (exceeds 250 allowed). Consider refactoring. Open
from __future__ import annotations
import ast
import builtins
import sys
Function visit_FunctionDef
has a Cognitive Complexity of 117 (exceeds 5 allowed). Consider refactoring. Open
def visit_FunctionDef(
self, node: FunctionDef | AsyncFunctionDef
) -> FunctionDef | AsyncFunctionDef | None:
"""
Injects type checks for function arguments, and for a return of None if the
- 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_Assign
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
def visit_Assign(self, node: Assign) -> Any:
"""
This injects a type check into a local variable assignment within a function
body. The variable must have been annotated earlier in the function body.
- 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 _use_memo
has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring. Open
def _use_memo(
self, node: ClassDef | FunctionDef | AsyncFunctionDef
) -> Generator[None, Any, None]:
new_memo = TransformMemo(node, self._memo, self._memo.path + (node.name,))
old_memo = self._memo
- 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 35 (exceeds 5 allowed). Consider refactoring. Open
def visit_Subscript(self, node: Subscript) -> Any:
if self._memo.is_ignored_name(node.value):
return None
# The subscript of typing(_extensions).Literal can be any arbitrary string, so
- 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
TypeguardTransformer
has 21 functions (exceeds 20 allowed). Consider refactoring. Open
class TypeguardTransformer(NodeTransformer):
def __init__(
self, target_path: Sequence[str] | None = None, target_lineno: int | None = None
) -> None:
self._target_path = tuple(target_path) if target_path else None
Function __post_init__
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def __post_init__(self) -> None:
elements: list[str] = []
memo = self
while isinstance(memo.node, (ClassDef, FunctionDef, AsyncFunctionDef)):
elements.insert(0, memo.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
Function name_matches
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
def name_matches(self, expression: expr | Expr | None, *names: str) -> bool:
if expression is None:
return False
path: list[str] = []
- 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_BinOp
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def visit_BinOp(self, node: BinOp) -> Any:
self.generic_visit(node)
if isinstance(node.op, BitOr):
# If either branch of the BinOp has been transformed to `None`, it means
- 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 sys.version_info < (3, 9):
subscript_slice = Index(subscript_slice, ctx=Load())
Avoid deeply nested control flow statements. Open
if sys.version_info < (3, 9):
subscript_slice = Index(subscript_slice, ctx=Load())
Avoid deeply nested control flow statements. Open
if len(items) > 1:
new_memo.send_annotation = self._convert_annotation(
items[1]
)
Avoid deeply nested control flow statements. Open
if len(items) > 2:
new_memo.return_annotation = self._convert_annotation(
items[2]
)
else:
Avoid deeply nested control flow statements. Open
if node.args.args:
if node.name == "__new__":
memo_kwargs["self_type"] = Name(
id=node.args.args[0].arg, ctx=Load()
)
Avoid deeply nested control flow statements. Open
if isinstance(decorator, Call) and decorator.keywords:
self._memo.configuration_overrides = {
kw.arg: kw.value for kw in decorator.keywords if kw.arg
}
Avoid deeply nested control flow statements. Open
if (
isinstance(decorator, Name)
and decorator.id == "staticmethod"
):
break
Avoid deeply nested control flow statements. Open
if expression is None:
item[key] = self._get_import("typing", "Any")
Avoid deeply nested control flow statements. Open
if isinstance(annotation_slice, Index):
annotation_slice = (
annotation_slice.value # type: ignore[attr-defined]
)
Function is_ignored_name
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def is_ignored_name(self, expression: expr | Expr | None) -> bool:
top_expression = (
expression.value if isinstance(expression, Expr) else expression
)
- 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 len(items) > 0:
new_memo.yield_annotation = self._convert_annotation(
items[0]
)
Avoid deeply nested control flow statements. Open
if sys.version_info >= (3, 9):
container = Name("tuple", ctx=Load())
else:
container = self._get_import("typing", "Tuple")
Avoid deeply nested control flow statements. Open
if annotation:
annotations_[Constant(name)] = annotation
check_required = True
else:
annotations_[Constant(name)] = None
Function visit_ClassDef
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
def visit_ClassDef(self, node: ClassDef) -> ClassDef | None:
self._memo.local_names.add(node.name)
# Eliminate top level classes not belonging to the target path
if (
- 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 sys.version_info >= (3, 9):
container = Name("dict", ctx=Load())
else:
container = self._get_import("typing", "Dict")
Avoid deeply nested control flow statements. Open
if isinstance(annotation_slice, Tuple):
items = annotation_slice.elts
else:
items = [annotation_slice]
Consider simplifying this complex logical expression. Open
if (
self._memo.return_annotation
and (not self._memo.is_async or not self._memo.has_yield_expressions)
and not isinstance(node.body[-1], Return)
and (
Function visit_AnnAssign
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def visit_AnnAssign(self, node: AnnAssign) -> Any:
"""
This injects a type check into a local variable annotation-assignment within a
function body.
- 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_Name
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
def visit_Name(self, node: Name) -> Any:
if self._memo.is_ignored_name(node):
return None
if sys.version_info < (3, 9):
- 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 too many return
statements within this function. Open
return node
Avoid too many return
statements within this function. Open
return node.value
Avoid too many return
statements within this function. Open
return node
Avoid too many return
statements within this function. Open
return node.value
Avoid too many return
statements within this function. Open
return False