ickc/pantable

View on GitHub
src/pantable/ast.py

Summary

Maintainability
F
1 wk
Test Coverage

File ast.py has 1565 lines of code (exceeds 250 allowed). Consider refactoring.
Open

from __future__ import annotations

import re
from dataclasses import MISSING, dataclass, field, fields
from fractions import Fraction
Severity: Major
Found in src/pantable/ast.py - About 4 days to fix

    Function parse_data_markdown has a Cognitive Complexity of 140 (exceeds 5 allowed). Consider refactoring.
    Open

        def parse_data_markdown(
            str_array: np.ndarray[np.str_],
            fancy_table: bool = False,
            ica_cell_pat=re.compile(r'^(\([0-9, ]+\))?({[^{}]*})?$'),
            fancy_table_pat=re.compile(r'^({[^{}]*})?? ?(---|===|___)? ?({[^{}]*})?$'),
    Severity: Minor
    Found in src/pantable/ast.py - About 2 days 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 normalize has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

        def normalize(self, shape: Tuple[int, int]):
            '''normalize
    
            assume the types are correct. Normalize what's beyond type-correctness.
    
    
    Severity: Minor
    Found in src/pantable/ast.py - About 6 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 to_str_array has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

        def to_str_array(self, fancy_table: bool = False) -> np.ndarray[np.str_]:
            '''construct a table with both content and ica together
            '''
            # prepend a column if fancy-table
            offset = int(fancy_table)
    Severity: Minor
    Found in src/pantable/ast.py - About 6 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 simplify has a Cognitive Complexity of 40 (exceeds 5 allowed). Consider refactoring.
    Open

        def simplify(self):
            '''Reduced equivalent attrs to simplest form
    
            e.g. from PanTableStr to PanCodeBlock should uses this
            '''
    Severity: Minor
    Found in src/pantable/ast.py - About 6 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_width has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
    Open

        def auto_width(
            self,
            override_width: bool = False,
            cell_width_func: Optional[Callable[[str], int]] = cell_width_func,
        ):
    Severity: Minor
    Found in src/pantable/ast.py - About 5 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

    PanTableAbstract has 25 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class PanTableAbstract:
        '''an abstract class of PanTables
        '''
    
        cells: Union[TableArray, np.ndarray[Union[ListContainer, str]]]
    Severity: Minor
    Found in src/pantable/ast.py - About 2 hrs to fix

      Function put has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def put(
              self,
              content: Union[ListContainer, str],
              row_span: int,
              col_span: int,
      Severity: Minor
      Found in src/pantable/ast.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 to_pantable has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
      Open

          def to_pantable(self) -> PanTable:
              '''return a PanTable representation of self
              '''
              # * 1st pass: assemble the caches
              cache_texts: Dict[Union[str, Tuple[str, int], Tuple[str, int, int]], str] = {}
      Severity: Minor
      Found in src/pantable/ast.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 __post_init__ has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def __post_init__(self):
              '''fall back to default if invalid type
      
              Only check for type here. e.g. positivity of width and table_width are not checked at this point.
              '''
      Severity: Minor
      Found in src/pantable/ast.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 to_pantablemarkdown has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

          def to_pantablemarkdown(self) -> PanTableMarkdown:
              '''return a PanTableMarkdown representation of self
              '''
              # * 1st pass: assemble the caches
              cache_elems: Dict[Union[str, Tuple[str, int], Tuple[str, int, int]], ListContainer] = {}
      Severity: Minor
      Found in src/pantable/ast.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 stringified has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          def stringified(self, width: int = 15, cannonical=True) -> TableArray:
              '''return stringified TableArray
      
              :param int width: width per column
              '''
      Severity: Minor
      Found in src/pantable/ast.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 __post_init__ has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
      Open

          def __post_init__(self):
              super().__post_init__()
      
              shape = self.shape
              m, n = shape
      Severity: Minor
      Found in src/pantable/ast.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 from_panflute_ast has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def from_panflute_ast(cls, table: Table) -> PanTable:
              ica_table = Ica(
                  table.identifier,
                  table.classes,
                  table.attributes,
      Severity: Minor
      Found in src/pantable/ast.py - About 1 hr to fix

        Function to_pantable has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def to_pantable(self) -> PanTable:
                '''return a PanTable representation of self
                '''
                # * 1st pass: assemble the caches
                cache_texts: Dict[Union[str, Tuple[str, int], Tuple[str, int, int]], str] = {}
        Severity: Minor
        Found in src/pantable/ast.py - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                                  if ica_:
                                      ica = ica_
                              else:
          Severity: Major
          Found in src/pantable/ast.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if cell_n_new > 1:
                                        temp[j + 1].append((width_int_resid, cell_n_new))
                                    else:
                                        temp[j + 1].append(width_int_resid)
            
            
            Severity: Major
            Found in src/pantable/ast.py - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if founds:
                                          found = founds[0]
                                          has_ica = True
                                          ica_temp = found[1]
                                          ica = f'[]{ica_temp}' if ica_temp else ''
              Severity: Major
              Found in src/pantable/ast.py - About 45 mins to fix

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

                    def put(
                Severity: Minor
                Found in src/pantable/ast.py - About 45 mins to fix

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

                      def from_panflute_ast(cls, table: Table) -> PanTable:
                          ica_table = Ica(
                              table.identifier,
                              table.classes,
                              table.attributes,
                  Severity: Minor
                  Found in src/pantable/ast.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 ica_row:
                                              icas_row[i] = f'[]{ica_row}'
                                      else:
                  Severity: Major
                  Found in src/pantable/ast.py - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if body_list and 'body' not in last_body:
                                                last_body['body'] = temp
                                            else:
                                                body_list.append({'body': temp})
                                        # is_body_head
                    Severity: Major
                    Found in src/pantable/ast.py - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if marker:
                                                  temp_markers.append(marker)
                                                  temp_icas.append(found[0])
                                                  temp_idxs.append(i)
                                              # * ignore the case that somone might put 2 attrs side-by-side
                      Severity: Major
                      Found in src/pantable/ast.py - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if ica_:
                                                    ica = ica_
                                            else:
                        Severity: Major
                        Found in src/pantable/ast.py - About 45 mins to fix

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

                              def to_spec(self, size: int) -> Spec:
                                  '''to Spec
                          
                                  assume normalized self.
                                  '''
                          Severity: Minor
                          Found in src/pantable/ast.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 to_pantable has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def to_pantable(self) -> PanTable:
                                  '''return a PanTable representation of self
                                  '''
                                  cells = self.cells
                                  contents = cells.contents
                          Severity: Minor
                          Found in src/pantable/ast.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 to_panflute_ast has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def to_panflute_ast(self) -> CodeBlock:
                                  '''return a panflute AST representation
                          
                                  TODO: handle differently if include exists and writable
                                  need to be able to configure pantable2csv on write location
                          Severity: Minor
                          Found in src/pantable/ast.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 cannonical has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def cannonical(self) -> TableArray:
                                  '''return a cell array where spanned cells appeared in cannonical location only
                          
                                  top-left corner of the grid is the cannonical location of a spanned cell
                                  '''
                          Severity: Minor
                          Found in src/pantable/ast.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 panflute_tablecells has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              def panflute_tablecells(self) -> np.ndarray[TableCell]:
                                  cells = self.cells
                                  contents = cells.contents
                                  shape = contents.shape
                                  m, n = shape
                          Severity: Minor
                          Found in src/pantable/ast.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