petspats/pyha

View on GitHub
pyha/common/core.py

Summary

Maintainability
F
3 days
Test Coverage

File core.py has 378 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
import sys
import time
import weakref
from collections import UserList
Severity: Minor
Found in pyha/common/core.py - About 5 hrs to fix

    Function __setitem__ has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
    Open

        def __setitem__(self, i, y):
            """ Implements auto-resize feature, ie resizes all assigns to Sfix registers.
            Also implements the register behaviour i.e saves assigned value to shadow variable, that is later used by the '_pyha_update_registers' function.
            """
            if hasattr(self.data[0], '_pyha_update_registers'):
    Severity: Minor
    Found in pyha/common/core.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 __setattr__ has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
    Open

        def __setattr__(self, name, value):
            """ Implements auto-resize feature, ie resizes all assigns to Sfix registers.
            Also implements the register behaviour i.e saves assigned value to shadow variable, that is later used by the '_pyha_update_registers' function.
            """
            if hasattr(self, '_pyha_is_initialization') or self._pyha_is_local() or not RegisterBehaviour.is_enabled():
    Severity: Minor
    Found in pyha/common/core.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 __call__ has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        def __call__(cls, *args, **kwargs):
            cls._pyha_is_initialization = True  # flag to avoid problems in __setattr__
            ret = super(Meta, cls).__call__(*args, **kwargs)
    
            if not SimulationRunning.is_enabled():  # local objects are simplified, they need no reset or register behaviour
    Severity: Minor
    Found in pyha/common/core.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 auto_resize has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
    Open

    def auto_resize(target, value):
        if not AutoResize.is_enabled() or not isinstance(target, (Sfix, Complex)) or Sfix._float_mode.enabled:
            return value
        if target.bits is not None:
            right = value.right
    Severity: Minor
    Found in pyha/common/core.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 update_input_types has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def update_input_types(self, args, kwargs):
            if self.arg_types is None:
                self.arg_types = list(args)
            else:
                for i, v in enumerate(args):
    Severity: Minor
    Found in pyha/common/core.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 __deepcopy__ has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def __deepcopy__(self, memo):
            cls = self.__class__
            result = cls.__new__(cls)
            memo[id(self)] = result
    
    
    Severity: Minor
    Found in pyha/common/core.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 _pyha_floats_to_fixed has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def _pyha_floats_to_fixed(self, silence=False):
            """ Go over the datamodel and convert floats to sfix, this is done before RTL/GATE simulation """
            from pyha.common.complex import default_complex
            # update atoms
            for k, v in self.__dict__.items():
    Severity: Minor
    Found in pyha/common/core.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 _pyha_floats_to_fixed has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def _pyha_floats_to_fixed(self, silence=False):
            """ Go over the datamodel and convert floats to sfix, this is done before RTL/GATE simulation """
            from pyha.common.complex import default_complex
            if hasattr(self.data[0], '_pyha_update_registers'):  # is submodule
                for x in self.data:
    Severity: Minor
    Found in pyha/common/core.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 _pyha_enable_function_profiling_for_types has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def _pyha_enable_function_profiling_for_types(self):
            for k, v in self.__dict__.items():
                if k == '_pyha_initial_self':
                    continue
                if hasattr(v, '_pyha_update_registers'):
    Severity: Minor
    Found in pyha/common/core.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 _pyha_insert_tracer has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def _pyha_insert_tracer(self, label=''):
            from pyha.simulation.tracer import Tracer
            for k, v in self.__dict__.items():
                if k == '_pyha_initial_self':
                    continue
    Severity: Minor
    Found in pyha/common/core.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 update_output_types has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def update_output_types(self, ret):
            ret = get_iterable(ret)
            if self.output_types is None:
                if isinstance(ret, tuple):
                    self.outputs_is_tuple = True
    Severity: Minor
    Found in pyha/common/core.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 k.startswith('_pyha'):
                                continue
                            # elif local and isinstance(v, PyhaFunc): # PyhaFunc MUST be copied for initial objects...everything breaks otherwise
                            #     continue
                            else:
    Severity: Major
    Found in pyha/common/core.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              if k.startswith('_pyha'):
                                  continue
                              elem.__dict__['_pyha_next'][k] = v
      Severity: Major
      Found in pyha/common/core.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                                if k == '_pyha_initial_self' or k == '_pyha_next' or isinstance(v,
                                                                                                Hardware):  # dont waste time on endless deepcopy
                                    setattr(result, k, copy(v))
                                    # print(k, v)
                                else:
        Severity: Major
        Found in pyha/common/core.py - About 45 mins to fix

          There are no issues that match your filters.

          Category
          Status