giganticode/codeprep

View on GitHub
codeprep/bpepkg/wild_bpe.py

Summary

Maintainability
F
3 days
Test Coverage

Function update_neighbour_index has a Cognitive Complexity of 42 (exceeds 5 allowed). Consider refactoring.
Open

def update_neighbour_index(location_index, neighbour_index, pair_to_merge):
    for side in Side:
        disappearing_pairs = neighbour_index[pair_to_merge][side]
        for disappearing_pair in disappearing_pairs:
            if can_be_concat(disappearing_pair, pair_to_merge, side):
Severity: Minor
Found in codeprep/bpepkg/wild_bpe.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

File wild_bpe.py has 395 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# SPDX-FileCopyrightText: 2020 Hlib Babii <hlibbabii@gmail.com>
#
# SPDX-License-Identifier: Apache-2.0

import logging
Severity: Minor
Found in codeprep/bpepkg/wild_bpe.py - About 5 hrs to fix

    Function update_location_index has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
    Open

    def update_location_index(location_index, neighbour_index, pair_to_merge):
        occurence_changes = []
        disappearing_pairs = neighbour_index[pair_to_merge]
        main_list = location_index[pair_to_merge]
        if pair_to_merge in neighbour_index[pair_to_merge][Side.any()]:
    Severity: Minor
    Found in codeprep/bpepkg/wild_bpe.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 run has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
    Open

    def run(generator: Generator[str, None, None], n_merges: int=sys.maxsize,
            include_performance_stats_every_n_merges: int = 0) \
            -> Tuple[str, int, Optional[List[BpePerformanceStatsEntry]]]:
    
        checkpoint = time.time()
    Severity: Minor
    Found in codeprep/bpepkg/wild_bpe.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 merge_lists_both has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
    Open

    def merge_lists_both(main_list: List[int], list2: List[int], position_shift: Tuple[int, int]) -> Tuple[List[int], List[int]]:
        """
        >>> merge_lists_both([0, 5, 7, 11, 16], [1, 9, 15], (2, -2))
        ([1, 15], [7])
    
    
    Severity: Minor
    Found in codeprep/bpepkg/wild_bpe.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 get_char_iterator_for_dir has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

    def get_char_iterator_for_dir(path_to_dir: str) -> Generator[str, None, None]:
        for root, dirs, files in os.walk(path_to_dir):
            for file in files:
                if file.endswith('.py'):
                    yield from get_char_iterator_for_file(os.path.join(root, file))
    Severity: Minor
    Found in codeprep/bpepkg/wild_bpe.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 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def __init__(self, merges_done: int, time_for_last_merge: float,
    Severity: Major
    Found in codeprep/bpepkg/wild_bpe.py - About 50 mins to fix

      Avoid deeply nested control flow statements.
      Open

                          if can_be_concat(pair_to_merge, cc, op_side.opposite()):
                              cc_concat = concat_pairs(pair_to_merge, cc, op_side.opposite())
                              add_pairs_to_neighbour_index(neighbour_index, appeared_pair, cc_concat, op_side,
                                                           location_index)
      
      
      Severity: Major
      Found in codeprep/bpepkg/wild_bpe.py - About 45 mins to fix

        Avoid deeply nested control flow statements.
        Open

                            for disappeared_pair2 in disappearing_pairs:
                                mm = concat_pairs(pair_to_merge, disappeared_pair2, side)
                                add_pairs_to_neighbour_index(neighbour_index, appeared_pair, mm, side, location_index)
                                if can_be_concat(pair_to_merge, mm, side.opposite()):
                                    mm_concat = concat_pairs(pair_to_merge, mm, side.opposite())
        Severity: Major
        Found in codeprep/bpepkg/wild_bpe.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                              if can_be_concat(pair_to_merge, neighbour_of_neighbour, side.opposite()):
                                  neighbour_of_neighbour_concat = concat_pairs(pair_to_merge, neighbour_of_neighbour,
                                                                               side.opposite())
                                  add_pairs_to_neighbour_index(neighbour_index, appeared_pair, neighbour_of_neighbour_concat,
                                                               side, location_index)
          Severity: Major
          Found in codeprep/bpepkg/wild_bpe.py - About 45 mins to fix

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

            def add_pairs_to_neighbour_index(index, pair1, pair2, side, location_index):
            Severity: Minor
            Found in codeprep/bpepkg/wild_bpe.py - About 35 mins to fix

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

              def cleanup_location_index(location_index, most_freq_pair, disappearing_pairs):
                  for side in Side:
                      for disappearing_pair in disappearing_pairs[side]:
                          if len(location_index[disappearing_pair]) == 0:
                              del location_index[disappearing_pair]
              Severity: Minor
              Found in codeprep/bpepkg/wild_bpe.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 cleanup_neighbour_index has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

              def cleanup_neighbour_index(location_index, neighbour_index, most_freq_pair):
                  for side in Side:
                      disappearing_pairs = neighbour_index[most_freq_pair][side]
                      for disappearing_pair in disappearing_pairs:
                          if disappearing_pair not in location_index and disappearing_pair in neighbour_index:
              Severity: Minor
              Found in codeprep/bpepkg/wild_bpe.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

              There are no issues that match your filters.

              Category
              Status