rjdbcm/Aspidites

View on GitHub

Showing 46 of 50 total issues

Cyclomatic complexity is too high in method compile_object. (6)
Open

    def compile_object(self) -> None:
        glob_so = str(self.app_name) + ".*.so"
        opt = "-q" if not self.args.verbose else ""
        setup_py = str(Path(self.root) / "setup.py")
        setup_runner = f"{sys.executable} {setup_py} {opt} build_ext -b ."
Severity: Minor
Found in Aspidites/api/compiler.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Cyclomatic complexity is too high in method handle_names. (6)
Open

    def handle_names(self):
        prevname = ""
        for name in self.names:
            if name[:3] == "do_":
                if name == prevname:
Severity: Minor
Found in Aspidites/api/repl.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

Function cvt_arith_expr has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

def cvt_arith_expr(s, loc, t):
    expr = "".join((str(i) for i in t))
    substr = ["!", "**", "//", "/", "%", '*' '-', '+']
    handler = {
        lambda x: "!" in x: factorial,
Severity: Minor
Found in Aspidites/api/convert.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 input has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def input(self):
        self.stdout.flush()

        line = input(START_PROMPT)
        if "))" in line and line.endswith(tuple(Extension.registrar.keys()) + ("*",)):
Severity: Minor
Found in Aspidites/api/repl.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 __exit__ has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    def __exit__(self, exc_type, exc_val, exc_tb):
        self.part_file.close()
        if exc_type:
            if self.rm_part_on_exc:
                try:
Severity: Minor
Found in Aspidites/woma/fileutils.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 handle_names has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def handle_names(self):
        prevname = ""
        for name in self.names:
            if name[:3] == "do_":
                if name == prevname:
Severity: Minor
Found in Aspidites/api/repl.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 SafeExp has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

def SafeExp(a, b):
    if (
        (a == 0 and b == 0) or (isinf(a) and b == 0) or (isinf(b) and a == 0)
    ):  # pragma: no cover
        return Undefined(SafeExp, a, b)
Severity: Minor
Found in Aspidites/api/math.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 replace has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def replace(src, dst):
        # argument names match stdlib docs, docstring below
        try:
            # ReplaceFile fails if the dest file does not exist, so
            # first try to rename it into position
Severity: Minor
Found in Aspidites/woma/fileutils.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 maybe_call has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

def maybe_call(instance, func, args, kwargs, _warn, warn_undefined):
Severity: Minor
Found in Aspidites/api/monads.py - About 45 mins to fix

    Consider simplifying this complex logical expression.
    Open

        if (
            (a == 0 and b == 0) or (isinf(a) and b == 0) or (isinf(b) and a == 0)
        ):  # pragma: no cover
            return Undefined(SafeExp, a, b)
        try:
    Severity: Major
    Found in Aspidites/api/math.py - About 40 mins to fix

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

      def _wrap_lines(text, padchar, width, wrapped_lines, pad):
      Severity: Minor
      Found in Aspidites/api/api.py - About 35 mins to fix

        Function __init__ has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            def __init__(self, compile_args: CompilerArgs):
                self.args = compile_args
                self.file_stack = CheckedFileStack()
                self.fname = Path(self.args.fname)
                if str(self.fname).endswith(".py"):
        Severity: Minor
        Found in Aspidites/api/compiler.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 maybe_call has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        def maybe_call(instance, func, args, kwargs, _warn, warn_undefined):
            e: Exception
            w: str
            warn_undefined: bool
            try:
        Severity: Minor
        Found in Aspidites/api/monads.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 get_all has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        def get_all(type_obj, include_subtypes=True):
            """Get a list containing all instances of a given type.  This will
            work for the vast majority of types out there.
        
            >>> RatKing = type('Ratking', {})
        Severity: Minor
        Found in Aspidites/woma/gcutils.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 setup_test_env has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

        def setup_test_env(argv):
            if len(argv) >= 2 and argv[1] == "--pytest" or argv[1] == "-pt":  # pragma: no cover
                if not os.getenv("ASPIDITES_DOCKER_BUILD"):
                    argv = [
                        str(Path(__file__).absolute().parent / Path("tests/test_aspidites.py"))
        Severity: Minor
        Found in Aspidites/__main__.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

        Try, Except, Pass detected.
        Open

                        except Exception:
        Severity: Info
        Found in Aspidites/woma/fileutils.py by bandit

        Starting a process with a shell, possible injection detected, security issue.
        Open

                os.system("cls" if os.name == "nt" else "clear")
        Severity: Major
        Found in Aspidites/api/repl.py by bandit

        The input method in Python 2 will read from standard input, evaluate and run the resulting string as python source code. This is similar, though in many ways worse, then using eval. On Python 2, use raw_input instead, input is safe in Python 3.
        Open

                line = input(START_PROMPT)
        Severity: Major
        Found in Aspidites/api/repl.py by bandit

        Consider possible security implications associated with pickle module.
        Open

        import pickle
        Severity: Info
        Found in Aspidites/woma/pickleutils.py by bandit

        Use of possibly insecure function - consider using safer ast.literal_eval.
        Open

                    out = eval(
                        compile(x, filename="<inline code>", mode="eval"),
                        self.__locals__,
                        self.__locals__,
        Severity: Minor
        Found in Aspidites/api/repl.py by bandit
        Severity
        Category
        Status
        Source
        Language