chrislit/abydos

View on GitHub
abydos/distance/_aline.py

Summary

Maintainability
F
1 wk
Test Coverage

File _aline.py has 1627 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# Copyright 2019-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: Major
Found in abydos/distance/_aline.py - About 4 days to fix

    Function alignments has a Cognitive Complexity of 171 (exceeds 5 allowed). Consider refactoring.
    Open

        def alignments(
            self, src: str, tar: str, score_only: bool = False
        ) -> Union[float, List[Tuple[float, str, str]]]:
            """Return the ALINE alignments of two strings.
    
    
    Severity: Minor
    Found in abydos/distance/_aline.py - About 3 days 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 alignments. (52)
    Open

        def alignments(
            self, src: str, tar: str, score_only: bool = False
        ) -> Union[float, List[Tuple[float, str, str]]]:
            """Return the ALINE alignments of two strings.
    
    
    Severity: Minor
    Found in abydos/distance/_aline.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

    Cyclomatic complexity is too high in class ALINE. (12)
    Open

    class ALINE(_Distance):
        r"""ALINE alignment, similarity, and distance.
    
        ALINE alignment was developed by
        :cite:`Kondrak:2000,Kondrak:2002,Downey:2008`, and establishes an
    Severity: Minor
    Found in abydos/distance/_aline.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 alignments has 37 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def alignments(
            self, src: str, tar: str, score_only: bool = False
        ) -> Union[float, List[Tuple[float, str, str]]]:
            """Return the ALINE alignments of two strings.
    
    
    Severity: Minor
    Found in abydos/distance/_aline.py - About 1 hr to fix

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

          def __init__(
      Severity: Major
      Found in abydos/distance/_aline.py - About 1 hr to fix

        Avoid deeply nested control flow statements.
        Open

                                if i == src_len or j == tar_len:
                                    sg_max = s_mat[i, j]
                            else:
        Severity: Major
        Found in abydos/distance/_aline.py - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  for key, value in tar_feat[i].items():
                                      if key != 'supplemental':
                                          tar_feat[j][key] = value
                                  j = 0
          Severity: Major
          Found in abydos/distance/_aline.py - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    for key, value in src_feat[i].items():
                                        if key != 'supplemental':
                                            src_feat[j][key] = value
                                    j = 0
            Severity: Major
            Found in abydos/distance/_aline.py - About 45 mins to fix

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

                  def alignments(
              Severity: Critical
              Found in abydos/distance/_aline.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

              Method "__init__" has 10 parameters, which is greater than the 7 authorized.
              Open

                      self,
                      epsilon: float = 0.0,
                      c_skip: float = -10,
                      c_sub: float = 35,
                      c_exp: float = 45,
              Severity: Major
              Found in abydos/distance/_aline.py by sonar-python

              A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.

              Noncompliant Code Example

              With a maximum number of 4 parameters:

              def do_something(param1, param2, param3, param4, param5):
                  ...
              

              Compliant Solution

              def do_something(param1, param2, param3, param4):
                  ...
              

              Too many branches (41/12)
              Open

                  def alignments(
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when a function or method has too many branches, making it hard to follow.

              Too many nested blocks (6/5)
              Open

                      for i in range(1, len(src_feat)):
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when a function or a method has too many nested blocks. This makes the code less understandable and maintainable.

              Unnecessary else after return
              Open

                          if s_mat[i, j] == 0:
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used in order to highlight an unnecessary block of code following an if containing a return statement. As such, it will warn when it encounters an else following a chain of ifs, all of them containing a return statement.

              Too many statements (62/50)
              Open

                      def _retrieve(
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when a function or method has too many statements. You should then split it in smaller functions / methods.

              Too many instance attributes (8/7)
              Open

              class ALINE(_Distance):
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when class has too many instance attributes, try to reduce this to get a simpler (and so easier to use) class.

              Too many arguments (9/5)
              Open

                  def __init__(
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when a function or method takes too many arguments.

              Too many local variables (33/15)
              Open

                  def alignments(
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when a function or method has too many local variables.

              Too many nested blocks (6/5)
              Open

                      for i in range(1, len(tar_feat)):
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when a function or a method has too many nested blocks. This makes the code less understandable and maintainable.

              Too many statements (136/50)
              Open

                  def alignments(
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when a function or method has too many statements. You should then split it in smaller functions / methods.

              Useless return at end of function or method
              Open

                          def _record(score: float, out: List[Tuple[str, str]]) -> None:
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Emitted when a single return or return None statement is found at the end of function or method definition. This statement can safely be removed because Python will implicitly return None

              Unable to import 'numpy'
              Open

              from numpy import float_, inf, zeros
              Severity: Critical
              Found in abydos/distance/_aline.py by pylint

              Used when pylint has been unable to import a module.

              Unused argument 'args'
              Open

                      def _sig_skip(*args: Any) -> float:
              Severity: Minor
              Found in abydos/distance/_aline.py by pylint

              Used when a function or method argument is not used.

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

                          seg1: Dict[str, float],
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO seg1: Dict[str, float], ^ |

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

                      self,
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO self, ^ |

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

                                  i < src_len and j < tar_len
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO i < srclen and j < tarlen ^ |

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

                      phones: str = 'aline',
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO phones: str = 'aline', ^ |

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

                                  and s_mat[i - 2, j - 1]
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO and s_mat[i - 2, j - 1] ^ |

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

                          seg2b: Dict[str, float],
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO seg2b: Dict[str, float], ^ |

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

                      mode: str = 'local',
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO mode: str = 'local', ^ |

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

                                  + _sig_exp(
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO + sigexp( ^ |

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

                      epsilon: float = 0.0,
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO epsilon: float = 0.0, ^ |

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

                                  and j > 0
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO and j > 0 ^ |

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

                      **kwargs: Any
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO **kwargs: Any ^ |

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

                      c_exp: float = 45,
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO c_exp: float = 45, ^ |

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

                                  i > 0
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO i > 0 ^ |

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

                      normalizer: Callable[[List[float]], float] = max,
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO normalizer: Callable[[List[float]], float] = max, ^ |

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

                      c_vwl: float = 10,
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO c_vwl: float = 10, ^ |

              Variable name j1 doesn't conform to snake_case naming style
              Open

                                  for j1 in range(tar_len - 1, j - 1, -1):
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

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

                                  and s_mat[i - 1, j - 1]
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO and s_mat[i - 1, j - 1] ^ |

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

                      c_skip: float = -10,
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO c_skip: float = -10, ^ |

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

                          i: int, j: int, score: float, out: List[Tuple[str, str]]
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO i: int, j: int, score: float, out: List[Tuple[str, str]] ^ |

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

                          seg2a: Dict[str, float],
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO seg2a: Dict[str, float], ^ |

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

                      c_sub: float = 35,
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO c_sub: float = 35, ^ |

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

                                  + _sig_exp(
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO + sigexp( ^ |

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

                                  and j > 1
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO and j > 1 ^ |

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

                                  + score
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO + score ^ |

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

                                  + score
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO + score ^ |

              Too many lines in module (1747/1000)
              Open

              # Copyright 2019-2020 by Christopher C. Little.
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when a module has too many lines, reducing its readability.

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

                                  >= threshold
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO

              = threshold ^ |

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

                                  and j > 0
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO and j > 0 ^ |

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

                                  i < src_len or j < tar_len
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO i < srclen or j < tarlen ^ |

              Variable name j1 doesn't conform to snake_case naming style
              Open

                              for j1 in range(j - 1, -1, -1):
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

              Variable name ss doesn't conform to snake_case naming style
              Open

                              for ss, ts in out:
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

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

                                  i > 0
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO i > 0 ^ |

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

                                  + _sig_sub(src_feat_wt[i - 1], tar_feat_wt[j - 1])
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO + sigsub(srcfeatwt[i - 1], tarfeatwt[j - 1]) ^ |

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

                                  >= threshold
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO

              = threshold ^ |

              Variable name i1 doesn't conform to snake_case naming style
              Open

                                  for i1 in range(src_len - 1, i - 1, -1):
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

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

                                  + score
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO + score ^ |

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

                                  and s_mat[i - 1, j - 2]
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO and s_mat[i - 1, j - 2] ^ |

              Variable name ch doesn't conform to snake_case naming style
              Open

                      for ch in src:
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

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

                      self, src: str, tar: str, score_only: bool = False
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO self, src: str, tar: str, score_only: bool = False ^ |

              Variable name ts doesn't conform to snake_case naming style
              Open

                              for ss, ts in out:
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

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

                                  >= threshold
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO

              = threshold ^ |

              Variable name f doesn't conform to snake_case naming style
              Open

                          for f in features:
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

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

                                  j > 0
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO j > 0 ^ |

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

                                  i > 0
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO i > 0 ^ |

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

                                  and s_mat[i - 1, j] + _sig_skip(src_tok[i - 1]) + score
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO and smat[i - 1, j] + _sigskip(src_tok[i - 1]) + score ^ |

              Variable name i1 doesn't conform to snake_case naming style
              Open

                              for i1 in range(i - 1, -1, -1):
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

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

                                  and s_mat[i, j - 1] + _sig_skip(tar_tok[j - 1]) + score
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO and smat[i, j - 1] + _sigskip(tar_tok[j - 1]) + score ^ |

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

                                  >= threshold
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO

              = threshold ^ |

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

                                  >= threshold
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO

              = threshold ^ |

              Variable name ch doesn't conform to snake_case naming style
              Open

                      for ch in tar:
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).

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

                                  i > 1
              Severity: Info
              Found in abydos/distance/_aline.py by pylint

              TODO i > 1 ^ |

              There are no issues that match your filters.

              Category
              Status