hadialqattan/pycln

View on GitHub
pycln/utils/scan.py

Summary

Maintainability
D
3 days
Test Coverage

SourceAnalyzer has 27 functions (exceeds 20 allowed). Consider refactoring.
Open

class SourceAnalyzer(ast.NodeVisitor):

    """AST source code analyzer.

    >>> import ast
Severity: Minor
Found in pycln/utils/scan.py - About 3 hrs to fix

    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):
    Severity: Minor
    Found in pycln/utils/scan.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 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
    Severity: Minor
    Found in pycln/utils/scan.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 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:
    Severity: Minor
    Found in pycln/utils/scan.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 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
    Severity: Minor
    Found in pycln/utils/scan.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 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.
    
    
    Severity: Minor
    Found in pycln/utils/scan.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 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
    Severity: Minor
    Found in pycln/utils/scan.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 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
    Severity: Minor
    Found in pycln/utils/scan.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 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
    Severity: Minor
    Found in pycln/utils/scan.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 _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:
    Severity: Minor
    Found in pycln/utils/scan.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 _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"
    Severity: Minor
    Found in pycln/utils/scan.py - About 55 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 _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"
    Severity: Minor
    Found in pycln/utils/scan.py - About 55 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 isinstance(item, ast.AST):
                                self.visit(item)
                    elif isinstance(value, ast.AST):
    Severity: Major
    Found in pycln/utils/scan.py - About 45 mins to fix

      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))
      Severity: Minor
      Found in pycln/utils/scan.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 isinstance(item, ast.AST):
                                  self.visit(item)
                      elif isinstance(value, ast.AST):
      Severity: Major
      Found in pycln/utils/scan.py - About 45 mins to fix

        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"):
        Severity: Minor
        Found in pycln/utils/scan.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 _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):
        Severity: Minor
        Found in pycln/utils/scan.py - About 25 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 _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.
        Severity: Minor
        Found in pycln/utils/scan.py - About 25 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_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.
                #:
        Severity: Minor
        Found in pycln/utils/scan.py - About 25 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_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)):
        Severity: Minor
        Found in pycln/utils/scan.py - About 25 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

        There are no issues that match your filters.

        Category
        Status