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
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
- Read upRead up
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)
- Read upRead up
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,
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):
- Read upRead up
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"