giganticode/codeprep

View on GitHub
codeprep/preprocess/tokens.py

Summary

Maintainability
D
1 day
Test Coverage

File tokens.py has 603 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

from abc import ABC, abstractmethod
Severity: Major
Found in codeprep/preprocess/tokens.py - About 1 day to fix

    Function __getitem__ has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def __getitem__(self, item: Union[int, slice]):
            start, stop = TokenSequence._normalize_index_or_slice(item, total=len(self))
    
            adjusted_before = 0
            adjusted_after = 0
    Severity: Minor
    Found in codeprep/preprocess/tokens.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 _normalize_index has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        def _normalize_index(index: Optional[int], is_slice: bool, total: int) -> Optional[int]:
            """
            >>> TokenSequence._normalize_index(None, is_slice=False, total=2) is None
            True
            >>> TokenSequence._normalize_index(-3, is_slice=False, total=2)
    Severity: Minor
    Found in codeprep/preprocess/tokens.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 create has 7 arguments (exceeds 4 allowed). Consider refactoring.
    Open

        def create(tokens: List[str] = None, metadata: PreppedTokenMetadata = None,
    Severity: Major
    Found in codeprep/preprocess/tokens.py - About 50 mins to fix

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

          def _normalize_index_or_slice(item: Union[int, slice], total: int) -> Tuple[int, int]:
              if isinstance(item, int):
                  start = TokenSequence._normalize_index(item, is_slice=False, total=total)
                  stop = start + 1 if start < total else start
              elif isinstance(item, slice):
      Severity: Minor
      Found in codeprep/preprocess/tokens.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