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
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.
- 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
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.
- Read upRead up
- Exclude checks
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. |
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
- Read upRead up
- Exclude checks
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. |
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.
Function __init__
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
def __init__(
Avoid deeply nested control flow statements. Open
if i == src_len or j == tar_len:
sg_max = s_mat[i, j]
else:
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
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
Refactor this function to reduce its Cognitive Complexity from 170 to the 15 allowed. Open
def alignments(
- Read upRead up
- Exclude checks
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,
- Read upRead up
- Exclude checks
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(
- Read upRead up
- Exclude checks
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)):
- Read upRead up
- Exclude checks
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:
- Read upRead up
- Exclude checks
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(
- Read upRead up
- Exclude checks
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):
- Read upRead up
- Exclude checks
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__(
- Read upRead up
- Exclude checks
Used when a function or method takes too many arguments.
Too many local variables (33/15) Open
def alignments(
- Read upRead up
- Exclude checks
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)):
- Read upRead up
- Exclude checks
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(
- Read upRead up
- Exclude checks
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:
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
Used when pylint has been unable to import a module.
Unused argument 'args' Open
def _sig_skip(*args: Any) -> float:
- Read upRead up
- Exclude checks
Used when a function or method argument is not used.
Wrong hanging indentation before block (add 4 spaces). Open
seg1: Dict[str, float],
- Read upRead up
- Exclude checks
TODO seg1: Dict[str, float], ^ |
Wrong hanging indentation before block (add 4 spaces). Open
self,
- Read upRead up
- Exclude checks
TODO self, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
i < src_len and j < tar_len
- Read upRead up
- Exclude checks
TODO i < srclen and j < tarlen ^ |
Wrong hanging indentation before block (add 4 spaces). Open
phones: str = 'aline',
- Read upRead up
- Exclude checks
TODO phones: str = 'aline', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and s_mat[i - 2, j - 1]
- Read upRead up
- Exclude checks
TODO and s_mat[i - 2, j - 1] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
seg2b: Dict[str, float],
- Read upRead up
- Exclude checks
TODO seg2b: Dict[str, float], ^ |
Wrong hanging indentation before block (add 4 spaces). Open
mode: str = 'local',
- Read upRead up
- Exclude checks
TODO mode: str = 'local', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
+ _sig_exp(
- Read upRead up
- Exclude checks
TODO + sigexp( ^ |
Wrong hanging indentation before block (add 4 spaces). Open
epsilon: float = 0.0,
- Read upRead up
- Exclude checks
TODO epsilon: float = 0.0, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and j > 0
- Read upRead up
- Exclude checks
TODO and j > 0 ^ |
Wrong hanging indentation before block (add 4 spaces). Open
**kwargs: Any
- Read upRead up
- Exclude checks
TODO **kwargs: Any ^ |
Wrong hanging indentation before block (add 4 spaces). Open
c_exp: float = 45,
- Read upRead up
- Exclude checks
TODO c_exp: float = 45, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
i > 0
- Read upRead up
- Exclude checks
TODO i > 0 ^ |
Wrong hanging indentation before block (add 4 spaces). Open
normalizer: Callable[[List[float]], float] = max,
- Read upRead up
- Exclude checks
TODO normalizer: Callable[[List[float]], float] = max, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
c_vwl: float = 10,
- Read upRead up
- Exclude checks
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):
- Read upRead up
- Exclude checks
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]
- Read upRead up
- Exclude checks
TODO and s_mat[i - 1, j - 1] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
c_skip: float = -10,
- Read upRead up
- Exclude checks
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]]
- Read upRead up
- Exclude checks
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],
- Read upRead up
- Exclude checks
TODO seg2a: Dict[str, float], ^ |
Wrong hanging indentation before block (add 4 spaces). Open
c_sub: float = 35,
- Read upRead up
- Exclude checks
TODO c_sub: float = 35, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
+ _sig_exp(
- Read upRead up
- Exclude checks
TODO + sigexp( ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and j > 1
- Read upRead up
- Exclude checks
TODO and j > 1 ^ |
Wrong hanging indentation before block (add 4 spaces). Open
+ score
- Read upRead up
- Exclude checks
TODO + score ^ |
Wrong hanging indentation before block (add 4 spaces). Open
+ score
- Read upRead up
- Exclude checks
TODO + score ^ |
Too many lines in module (1747/1000) Open
# Copyright 2019-2020 by Christopher C. Little.
- Read upRead up
- Exclude checks
Used when a module has too many lines, reducing its readability.
Wrong hanging indentation before block (add 4 spaces). Open
>= threshold
- Read upRead up
- Exclude checks
TODO
= threshold ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and j > 0
- Read upRead up
- Exclude checks
TODO and j > 0 ^ |
Wrong hanging indentation before block (add 4 spaces). Open
i < src_len or j < tar_len
- Read upRead up
- Exclude checks
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):
- Read upRead up
- Exclude checks
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:
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
TODO i > 0 ^ |
Wrong hanging indentation before block (add 4 spaces). Open
+ _sig_sub(src_feat_wt[i - 1], tar_feat_wt[j - 1])
- Read upRead up
- Exclude checks
TODO + sigsub(srcfeatwt[i - 1], tarfeatwt[j - 1]) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
>= threshold
- Read upRead up
- Exclude checks
TODO
= threshold ^ |
Variable name i1
doesn't conform to snake_case naming style Open
for i1 in range(src_len - 1, i - 1, -1):
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
TODO + score ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and s_mat[i - 1, j - 2]
- Read upRead up
- Exclude checks
TODO and s_mat[i - 1, j - 2] ^ |
Variable name ch
doesn't conform to snake_case naming style Open
for ch in src:
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
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:
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
TODO
= threshold ^ |
Variable name f
doesn't conform to snake_case naming style Open
for f in features:
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
TODO j > 0 ^ |
Wrong hanging indentation before block (add 4 spaces). Open
i > 0
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
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):
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
TODO and smat[i, j - 1] + _sigskip(tar_tok[j - 1]) + score ^ |
Wrong hanging indentation before block (add 4 spaces). Open
>= threshold
- Read upRead up
- Exclude checks
TODO
= threshold ^ |
Wrong hanging indentation before block (add 4 spaces). Open
>= threshold
- Read upRead up
- Exclude checks
TODO
= threshold ^ |
Variable name ch
doesn't conform to snake_case naming style Open
for ch in tar:
- Read upRead up
- Exclude checks
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
- Read upRead up
- Exclude checks
TODO i > 1 ^ |