agronholm/typeguard

View on GitHub
src/typeguard/_decorators.py

Summary

Maintainability
D
2 days
Test Coverage

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 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

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

Avoid deeply nested control flow statements.
Open

                    if is_method_of(property_func, target):
                        retval = instrument(property_func)
                        if isfunction(retval):
                            kwargs[name] = retval

Severity: Major
Found in src/typeguard/_decorators.py - About 45 mins to fix

    Function typechecked has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

    def typechecked(
    Severity: Minor
    Found in src/typeguard/_decorators.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if isfunction(retval):
                              wrapper = attr.__class__(retval)
                              setattr(target, key, wrapper)
                  elif isinstance(attr, property):
      Severity: Major
      Found in src/typeguard/_decorators.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if target_code:
                                return target_code
        
        
        Severity: Major
        Found in src/typeguard/_decorators.py - About 45 mins to fix

          Function typechecked has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

          def typechecked(
          Severity: Minor
          Found in src/typeguard/_decorators.py - About 35 mins to fix

            Avoid too many return statements within this function.
            Open

                    return "cannot find the target function in the AST"
            Severity: Major
            Found in src/typeguard/_decorators.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                      return retval
              Severity: Major
              Found in src/typeguard/_decorators.py - About 30 mins to fix

                Avoid too many return statements within this function.
                Open

                    return new_function
                Severity: Major
                Found in src/typeguard/_decorators.py - About 30 mins to fix

                  Avoid too many return statements within this function.
                  Open

                          return "instrumentor did not find the target function"
                  Severity: Major
                  Found in src/typeguard/_decorators.py - About 30 mins to fix

                    Avoid too many return statements within this function.
                    Open

                            return wrapper_class(retval)
                    Severity: Major
                    Found in src/typeguard/_decorators.py - About 30 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status