rasa/shared/core/training_data/structures.py

Summary

Maintainability
F
3 days
Test Coverage
B
83%

File structures.py has 650 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import json
import logging
from collections import deque, defaultdict

import uuid
Severity: Major
Found in rasa/shared/core/training_data/structures.py - About 1 day to fix

    Function with_cycles_removed has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring.
    Open

        def with_cycles_removed(self) -> "StoryGraph":
            """Create a graph with the cyclic edges removed from this graph."""
            story_end_checkpoints = self.story_end_checkpoints.copy()
            cyclic_edge_ids = self.cyclic_edge_ids
            # we need to remove the start steps and replace them with steps ending
    Severity: Minor
    Found in rasa/shared/core/training_data/structures.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 as_story_string has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
    Open

        def as_story_string(self, flat: bool = False, e2e: bool = False) -> Text:
            """Returns a story as a string."""
            # if the result should be flattened, we
            # will exclude the caption and any checkpoints.
            if flat:
    Severity: Minor
    Found in rasa/shared/core/training_data/structures.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 visualize has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        def visualize(self, output_file: Optional[Text] = None) -> "nx.MultiDiGraph":
            import networkx as nx
            from rasa.shared.core.training_data import visualization
            from colorhash import ColorHash
    
    
    Severity: Minor
    Found in rasa/shared/core/training_data/structures.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 topological_sort has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def topological_sort(
            graph: Dict[Text, Set[Text]]
        ) -> Tuple[deque, List[Tuple[Text, Text]]]:
            """Creates a top sort of a directed graph. This is an unstable sorting!
    
    
    Severity: Minor
    Found in rasa/shared/core/training_data/structures.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 _remove_unused_generated_cps has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
    Open

        def _remove_unused_generated_cps(
            self,
            story_steps: Dict[Text, StoryStep],
            overlapping_cps: Set[Text],
            story_end_checkpoints: Dict[Text, Text],
    Severity: Minor
    Found in rasa/shared/core/training_data/structures.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 __init__ has 6 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(
    Severity: Minor
    Found in rasa/shared/core/training_data/structures.py - About 45 mins to fix

      Avoid deeply nested control flow statements.
      Open

                              for cp in step.start_checkpoints:
                                  if cp.name == original_cp:
                                      if k == e:
                                          cp_name = source_cp_name
                                      else:
      Severity: Major
      Found in rasa/shared/core/training_data/structures.py - About 45 mins to fix

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

            def __init__(
        Severity: Minor
        Found in rasa/shared/core/training_data/structures.py - About 35 mins to fix

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

              def as_story_string(self, flat: bool = False, e2e: bool = False) -> Text:
                  story_content = ""
                  for step in self.story_steps:
                      story_content += step.as_story_string(flat, e2e)
          
          
          Severity: Minor
          Found in rasa/shared/core/training_data/structures.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 explicit_events has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
          Open

              def explicit_events(
                  self, domain: Domain, should_append_final_listen: bool = True
              ) -> List[Event]:
                  """Returns events contained in the story step including implicit events.
          
          
          Severity: Minor
          Found in rasa/shared/core/training_data/structures.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