chrislit/abydos

View on GitHub
abydos/corpus/_corpus.py

Summary

Maintainability
C
1 day
Test Coverage

Function __init__ has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
Open

    def __init__(
        self,
        corpus_text: str = '',
        doc_split: str = '\n\n',
        sent_split: str = '\n',
Severity: Minor
Found in abydos/corpus/_corpus.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

Cyclomatic complexity is too high in method __init__. (11)
Open

    def __init__(
        self,
        corpus_text: str = '',
        doc_split: str = '\n\n',
        sent_split: str = '\n',
Severity: Minor
Found in abydos/corpus/_corpus.py by radon

Cyclomatic Complexity

Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

Construct Effect on CC Reasoning
if +1 An if statement is a single decision.
elif +1 The elif statement adds another decision.
else +0 The else statement does not cause a new decision. The decision is at the if.
for +1 There is a decision at the start of the loop.
while +1 There is a decision at the while statement.
except +1 Each except branch adds a new conditional path of execution.
finally +0 The finally block is unconditionally executed.
with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
assert +1 The assert statement internally roughly equals a conditional statement.
Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

Source: http://radon.readthedocs.org/en/latest/intro.html

File _corpus.py has 264 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2014-2020 by Christopher C. Little.
# This file is part of Abydos.
#
# Abydos is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
Severity: Minor
Found in abydos/corpus/_corpus.py - About 2 hrs to fix

    Cyclomatic complexity is too high in method idf. (6)
    Open

        def idf(
            self, term: str, transform: Optional[Callable[[str], str]] = None
        ) -> float:
            r"""Calculate the Inverse Document Frequency of a term in the corpus.
    
    
    Severity: Minor
    Found in abydos/corpus/_corpus.py by radon

    Cyclomatic Complexity

    Cyclomatic Complexity corresponds to the number of decisions a block of code contains plus 1. This number (also called McCabe number) is equal to the number of linearly independent paths through the code. This number can be used as a guide when testing conditional logic in blocks.

    Radon analyzes the AST tree of a Python program to compute Cyclomatic Complexity. Statements have the following effects on Cyclomatic Complexity:

    Construct Effect on CC Reasoning
    if +1 An if statement is a single decision.
    elif +1 The elif statement adds another decision.
    else +0 The else statement does not cause a new decision. The decision is at the if.
    for +1 There is a decision at the start of the loop.
    while +1 There is a decision at the while statement.
    except +1 Each except branch adds a new conditional path of execution.
    finally +0 The finally block is unconditionally executed.
    with +1 The with statement roughly corresponds to a try/except block (see PEP 343 for details).
    assert +1 The assert statement internally roughly equals a conditional statement.
    Comprehension +1 A list/set/dict comprehension of generator expression is equivalent to a for loop.
    Boolean Operator +1 Every boolean operator (and, or) adds a decision point.

    Source: http://radon.readthedocs.org/en/latest/intro.html

    Function idf has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def idf(
            self, term: str, transform: Optional[Callable[[str], str]] = None
        ) -> float:
            r"""Calculate the Inverse Document Frequency of a term in the corpus.
    
    
    Severity: Minor
    Found in abydos/corpus/_corpus.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

    Avoid deeply nested control flow statements.
    Open

                            while word in sentence_words:
                                sentence_words.remove(word)
                    for char in set(filter_chars):
    Severity: Major
    Found in abydos/corpus/_corpus.py - About 45 mins to fix

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

          def __init__(
      Severity: Minor
      Found in abydos/corpus/_corpus.py - About 45 mins to fix

        Refactor this function to reduce its Cognitive Complexity from 27 to the 15 allowed.
        Open

            def __init__(
        Severity: Critical
        Found in abydos/corpus/_corpus.py by sonar-python

        Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.

        See

        Rename field "corpus"
        Open

                self.corpus = []  # type: List[List[List[str]]]
        Severity: Major
        Found in abydos/corpus/_corpus.py by sonar-python

        It's confusing to have a class member with the same name (case differences aside) as its enclosing class. This is particularly so when you consider the common practice of naming a class instance for the class itself.

        Best practice dictates that any field or member with the same name as the enclosing class be renamed to be more descriptive of the particular aspect of the class it represents or holds.

        Noncompliant Code Example

        class Foo:
          foo = ''
        
          def getFoo(self):
            ...
        
        foo = Foo()
        foo.getFoo() # what does this return?
        

        Compliant Solution

        class Foo:
          name = ''
        
          def getName(self):
            ...
        
        foo = Foo()
        foo.getName()
        

        Too many arguments (7/5)
        Open

            def __init__(
        Severity: Info
        Found in abydos/corpus/_corpus.py by pylint

        Used when a function or method takes too many arguments.

        Wrong hanging indentation before block (add 4 spaces).
        Open

                sent_split: str = '\n',
        Severity: Info
        Found in abydos/corpus/_corpus.py by pylint

        TODO sent_split: str = 'n', ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                filter_chars: Union[str, List[str], Set[str], Tuple[str]] = '',
        Severity: Info
        Found in abydos/corpus/_corpus.py by pylint

        TODO filter_chars: Union[str, List[str], Set[str], Tuple[str]] = '', ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                self, term: str, transform: Optional[Callable[[str], str]] = None
        Severity: Info
        Found in abydos/corpus/_corpus.py by pylint

        TODO self, term: str, transform: Optional[Callable[[str], str]] = None ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                stop_words: Optional[Union[List[str], Set[str], Tuple[str]]] = None,
        Severity: Info
        Found in abydos/corpus/_corpus.py by pylint

        TODO stop_words: Optional[Union[List[str], Set[str], Tuple[str]]] = None, ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                self,
        Severity: Info
        Found in abydos/corpus/_corpus.py by pylint

        TODO self, ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                doc_split: str = '\n\n',
        Severity: Info
        Found in abydos/corpus/_corpus.py by pylint

        TODO doc_split: str = 'nn', ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                corpus_text: str = '',
        Severity: Info
        Found in abydos/corpus/_corpus.py by pylint

        TODO corpus_text: str = '', ^ |

        Wrong hanging indentation before block (add 4 spaces).
        Open

                word_tokenizer: Optional[_Tokenizer] = None,
        Severity: Info
        Found in abydos/corpus/_corpus.py by pylint

        TODO wordtokenizer: Optional[Tokenizer] = None, ^ |

        There are no issues that match your filters.

        Category
        Status