agronholm/typeguard

View on GitHub

Showing 66 of 66 total issues

File _transformer.py has 981 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import annotations

import ast
import builtins
import sys
Severity: Major
Found in src/typeguard/_transformer.py - About 2 days to fix

    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
    Severity: Minor
    Found in src/typeguard/_transformer.py - About 2 days to fix

    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

    File _checkers.py has 769 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    from __future__ import annotations
    
    import collections.abc
    import inspect
    import sys
    Severity: Major
    Found in src/typeguard/_checkers.py - About 1 day to fix

      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.
      
      
      Severity: Minor
      Found in src/typeguard/_transformer.py - About 6 hrs to fix

      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 typechecked has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
      Open

      def typechecked(
          target: T_CallableOrType | None = None,
          *,
          forward_ref_policy: ForwardRefPolicy | Unset = unset,
          typecheck_fail_callback: TypeCheckFailCallback | Unset = unset,
      Severity: Minor
      Found in src/typeguard/_decorators.py - About 6 hrs to fix

      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
      Severity: Minor
      Found in src/typeguard/_transformer.py - About 6 hrs to fix

      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
      Severity: Minor
      Found in src/typeguard/_transformer.py - About 5 hrs to fix

      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 check_multi_variable_assignment has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
      Open

      def check_multi_variable_assignment(
          value: Any, targets: list[dict[str, Any]], memo: TypeCheckMemo
      ) -> Any:
          if max(len(target) for target in targets) == 1:
              iterated_values = [value]
      Severity: Minor
      Found in src/typeguard/_functions.py - About 3 hrs to fix

      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 check_callable has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

      def check_callable(
          value: Any,
          origin_type: Any,
          args: tuple[Any, ...],
          memo: TypeCheckMemo,
      Severity: Minor
      Found in src/typeguard/_checkers.py - About 3 hrs to fix

      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 find_target_function has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

      def find_target_function(
          new_code: CodeType, target_path: Sequence[str], firstlineno: int
      ) -> CodeType | None:
          target_name = target_path[0]
          for const in new_code.co_consts:
      Severity: Minor
      Found in src/typeguard/_decorators.py - About 2 hrs to fix

      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 instrument has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

      def instrument(f: T_CallableOrType) -> FunctionType | str:
          if not getattr(f, "__code__", None):
              return "no code associated"
          elif not getattr(f, "__module__", None):
              return "__module__ attribute is not set"
      Severity: Minor
      Found in src/typeguard/_decorators.py - About 2 hrs to fix

      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
      Severity: Minor
      Found in src/typeguard/_transformer.py - About 2 hrs to fix

        Function get_type_name has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

        def get_type_name(type_: Any) -> str:
            name: str
            for attrname in "__name__", "_name", "__forward_arg__":
                candidate = getattr(type_, attrname, None)
                if isinstance(candidate, str):
        Severity: Minor
        Found in src/typeguard/_utils.py - About 2 hrs to fix

        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

        File _functions.py has 252 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        from __future__ import annotations
        
        import sys
        import warnings
        from typing import Any, Callable, NoReturn, TypeVar, Union, overload
        Severity: Minor
        Found in src/typeguard/_functions.py - About 2 hrs to fix

          Function check_return_type has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

          def check_return_type(
              func_name: str,
              retval: T,
              annotation: Any,
              memo: TypeCheckMemo,
          Severity: Minor
          Found in src/typeguard/_functions.py - About 1 hr to fix

          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 __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)
          Severity: Minor
          Found in src/typeguard/_transformer.py - About 1 hr to fix

          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 check_argument_types has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

          def check_argument_types(
              func_name: str,
              arguments: dict[str, tuple[Any, Any]],
              memo: TypeCheckMemo,
          ) -> Literal[True]:
          Severity: Minor
          Found in src/typeguard/_functions.py - About 1 hr to fix

          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] = []
          Severity: Minor
          Found in src/typeguard/_transformer.py - About 1 hr to fix

          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 evaluate_forwardref has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              def evaluate_forwardref(forwardref: ForwardRef, memo: TypeCheckMemo) -> Any:
                  from ._union_transformer import compile_type_hint, type_substitutions
          
                  if not forwardref.__forward_evaluated__:
                      forwardref.__forward_code__ = compile_type_hint(forwardref.__forward_arg__)
          Severity: Minor
          Found in src/typeguard/_utils.py - About 1 hr to fix

          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 pytest_configure has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

          def pytest_configure(config: Config) -> None:
              def getoption(name: str) -> Any:
                  return config.getoption(name.replace("-", "_")) or config.getini(name)
          
              packages: list[str] | None = []
          Severity: Minor
          Found in src/typeguard/_pytest_plugin.py - About 1 hr to fix

          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

          Severity
          Category
          Status
          Source
          Language