agronholm/typeguard

View on GitHub

Showing 66 of 66 total issues

Function install_import_hook has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def install_import_hook(
    packages: Iterable[str] | None = None,
    *,
    cls: type[TypeguardFinder] = TypeguardFinder,
) -> ImportHookManager:
Severity: Minor
Found in src/typeguard/_importhook.py - About 45 mins 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_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 (
Severity: Minor
Found in src/typeguard/_transformer.py - About 45 mins 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 sys.version_info >= (3, 9):
                            container = Name("dict", ctx=Load())
                        else:
                            container = self._get_import("typing", "Dict")

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

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

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

      Avoid deeply nested control flow statements.
      Open

                              if isinstance(annotation_slice, Tuple):
                                  items = annotation_slice.elts
                              else:
                                  items = [annotation_slice]
      
      
      Severity: Major
      Found in src/typeguard/_transformer.py - About 45 mins to fix

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

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

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

          def check_type(
          Severity: Minor
          Found in src/typeguard/_functions.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

              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 (
              Severity: Major
              Found in src/typeguard/_transformer.py - About 40 mins to fix

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

                    def __init__(
                Severity: Minor
                Found in src/typeguard/_memo.py - About 35 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

                    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.
                    
                    
                    Severity: Minor
                    Found in src/typeguard/_transformer.py - About 35 mins 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_type has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                    def check_type(
                        value: object,
                        expected_type: Any,
                        *,
                        forward_ref_policy: ForwardRefPolicy = TypeCheckConfiguration().forward_ref_policy,
                    Severity: Minor
                    Found in src/typeguard/_functions.py - About 35 mins 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_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):
                    Severity: Minor
                    Found in src/typeguard/_transformer.py - About 35 mins 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 source_to_code has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def source_to_code(
                            data: Buffer | str | ast.Module | ast.Expression | ast.Interactive,
                            path: Buffer | str | PathLike[str] = "<string>",
                        ) -> CodeType:
                            if isinstance(data, (ast.Module, ast.Expression, ast.Interactive)):
                    Severity: Minor
                    Found in src/typeguard/_importhook.py - About 35 mins 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 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 node
                        Severity: Major
                        Found in src/typeguard/_transformer.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 node.value
                            Severity: Major
                            Found in src/typeguard/_transformer.py - About 30 mins to fix
                              Severity
                              Category
                              Status
                              Source
                              Language