petspats/pyha

View on GitHub
pyha/conversion/redbaron_transforms.py

Summary

Maintainability
F
1 wk
Test Coverage

File redbaron_transforms.py has 915 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import logging
import textwrap
from contextlib import suppress

from parse import parse
Severity: Major
Found in pyha/conversion/redbaron_transforms.py - About 2 days to fix

    Function transform_call has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
    Open

    def transform_call(red_node):
        """
        Converts Python style function calls to VHDL style:
        self.d(a) -> d(self, a)
    
    
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.py - About 1 day 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 transform_dynamic_lists has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring.
    Open

    def transform_dynamic_lists(red_node):
        data = VHDLModule('-', convert_obj)
    
        dynamic_lists = [x for x in data.elems if isinstance(x, VHDLList) and not x.elements_compatible_typed]
        for x in dynamic_lists:
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.py - About 1 day 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 transform_auto_resize has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
    Open

    def transform_auto_resize(red_node):
        """ Auto resize on Sfix assignments
         Examples (depend on initial Sfix type):
             self.sfix_reg = a        ->   self.sfix_reg = resize(a, 5, -29, fixed_wrap, fixed_round)
             self.sfix_list[0] = a    ->   self.sfix_list[0] = resize(a, 0, 0, fixed_saturate, fixed_round)
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.py - About 4 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 transform_resize_arguments has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def transform_resize_arguments(red_node):
        """ Replace 'wrap' -> fixed_wrap
            'saturate' -> fixed_saturate
            'truncate' -> fixed_truncate
            'round' -> fixed_round
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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 range_to_vhdl has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

        def range_to_vhdl(self, pyrange):
            # this for was transforemed by 'redbaron_pyfor_to_vhdl'
            if str(self.iterator) == '\\_i_\\':
                return f"{pyrange}'range"
    
    
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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 super_getattr has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
    Open

    def super_getattr(obj, attr, is_local=False):
        for part in attr.split('.'):
            if not is_local:
                if part == 'self' or part == 'self_next':
                    continue
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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 convert has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

    def convert(red: Node, obj=None):
        set_convert_obj(obj)
    
        # delete all non convertable functions from redbaron AST
        # coding style is akward because of some redbaron bugs...
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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 transform_unroll_local_constructor has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

    def transform_unroll_local_constructor(red_node):
        assigns = red_node.find_all('assign')
        for node in assigns:
            call = node.value.call
            if call is None:  # has no function call
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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 __init__ has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
    Open

        def __init__(self, red_node, parent=None):
            self.red_node = red_node
            self.parent = parent
            self.target = None
            self.value = None
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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 __str__ has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
    Open

        def __str__(self):
    
            # test if we are dealing with array appending ([a] + b)
            if self.value == '+':
                if isinstance(self.first, ListNodeVHDL) or isinstance(self.second, ListNodeVHDL):
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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 transform_registers has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def transform_registers(red_node):
        def add_next(x):
            if len(x) > 1 and str(x[0].value) == 'self':
                x[0].replace('self_next')
    
    
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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 transform_fixed_indexing_result_to_bool has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

    def transform_fixed_indexing_result_to_bool(red_node):
        """ VHDL indexing of fixed point value returns 'std_logic' type, this casts such assignments to bool() """
    
        nodes = red_node.find_all('atomtrailers')
    
    
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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 __str__ has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def __str__(self):
            base = '(' + ', '.join(str(x) for x in self.value) + ')'
    
            # find if this call is part of assignment node or AssociativeParenthesisNode
            p = self.red_node.parent
    Severity: Minor
    Found in pyha/conversion/redbaron_transforms.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

                            for i in range(len(x.elems)):
                                part.replace(f'{name}_{i}')
    
                                head = 'if' if i == 0 else 'elif'
                                new += f'{correct_indentation}\t{head} {index} == {i}:\n{correct_indentation}\t\t{line_node}\n'
    Severity: Major
    Found in pyha/conversion/redbaron_transforms.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              while True:
                                  if type(line_node.next) == EndlNode:
                                      break
                                  if hasattr(line_node.parent, 'value') and type(line_node.parent.value) == LineProxyList:
                                      if not (hasattr(line_node.parent, 'test') and (
      Severity: Major
      Found in pyha/conversion/redbaron_transforms.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            if not f:
                                continue
                            logger.warning(f'Not converting function {k}, was not called in simulation!')
        Severity: Major
        Found in pyha/conversion/redbaron_transforms.py - About 45 mins to fix

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

              def __str__(self):
                  ret = ''
                  for i, x in enumerate(self.value):
                      # add '.' infront if NameNode
                      new = '.{}' if isinstance(x, NameNodeVHDL) and i != 0 else '{}'
          Severity: Minor
          Found in pyha/conversion/redbaron_transforms.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 transform_multiple_assignment has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

          def transform_multiple_assignment(red_node):
              """ Multi target assigns to single target:
              a, b, c = 1, 2, 3 ->
              a = 1
              b = 2
          Severity: Minor
          Found in pyha/conversion/redbaron_transforms.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 f'{two_args[0].strip()} to ({two_args[1].strip()}) - 1'
          Severity: Major
          Found in pyha/conversion/redbaron_transforms.py - About 30 mins to fix

            Avoid too many return statements within this function.
            Open

                                    return f"0 to ({len[0]}'length{len[1]}) - 1"
            Severity: Major
            Found in pyha/conversion/redbaron_transforms.py - About 30 mins to fix

              Avoid too many return statements within this function.
              Open

                                  return f'0 to ({range_pattern[0]}) - 1'
              Severity: Major
              Found in pyha/conversion/redbaron_transforms.py - About 30 mins to fix

                Function get_object has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                Open

                def get_object(node):
                    """ Parse rebaron AtomTrailers node into Python object (taken from ongoing conversion object)
                     Works for object and local scope """
                
                    if len(node) > 1 and (node[0].value == 'self' or node[0].value == 'self_next'):
                Severity: Minor
                Found in pyha/conversion/redbaron_transforms.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