Function _group_linkage_intersection
has a Cognitive Complexity of 121 (exceeds 5 allowed). Consider refactoring. Open
def _group_linkage_intersection(self) -> TCounter[str]:
r"""Return the group linkage intersection of the tokens in src and tar.
This is based on group linkage, as defined by :cite:`On:2007`.
- 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
File _token_distance.py
has 780 lines of code (exceeds 250 allowed). Consider refactoring. Open
# Copyright 2018-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
Cyclomatic complexity is too high in method _group_linkage_intersection. (41) Open
def _group_linkage_intersection(self) -> TCounter[str]:
r"""Return the group linkage intersection of the tokens in src and tar.
This is based on group linkage, as defined by :cite:`On:2007`.
- 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 __init__
has a Cognitive Complexity of 44 (exceeds 5 allowed). Consider refactoring. Open
def __init__(
self,
tokenizer: Optional[_Tokenizer] = None,
intersection_type: str = 'crisp',
**kwargs: Any
- 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 __init__. (30) Open
def __init__(
self,
tokenizer: Optional[_Tokenizer] = None,
intersection_type: str = 'crisp',
**kwargs: Any
- 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. |
_TokenDistance
has 34 functions (exceeds 20 allowed). Consider refactoring. Open
class _TokenDistance(_Distance):
r"""Abstract Token Distance class.
.. _confusion_table:
Function _soft_intersection
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def _soft_intersection(self) -> TCounter[str]:
"""Return the soft source, target, & intersection tokens & weights.
This implements the soft intersection defined by :cite:`Russ:2014` in
a way that can reproduce the results in the paper.
- 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 _fuzzy_intersection. (7) Open
def _fuzzy_intersection(self) -> TCounter[str]:
r"""Return the fuzzy intersection of the tokens in src and tar.
This implements the fuzzy intersection defined by :cite:`Wang:2014`.
- 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 method _soft_intersection. (6) Open
def _soft_intersection(self) -> TCounter[str]:
"""Return the soft source, target, & intersection tokens & weights.
This implements the soft intersection defined by :cite:`Russ:2014` in
a way that can reproduce the results in the paper.
- 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 _fuzzy_intersection
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def _fuzzy_intersection(self) -> TCounter[str]:
r"""Return the fuzzy intersection of the tokens in src and tar.
This implements the fuzzy intersection defined by :cite:`Wang:2014`.
- 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
Avoid deeply nested control flow statements. Open
if not (col_covered[col] | row_covered[row]):
primed[row, col] = True
z_cols = (starred[row, :]).nonzero()[0]
if not z_cols.size:
step = 2
Avoid deeply nested control flow statements. Open
if not (col_covered[col] | row_covered[row]):
break
else:
Avoid deeply nested control flow statements. Open
for row in range(n):
if (
not (row_covered[row])
and arr[row, col] < h_val
):
Function _tokenize
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def _tokenize(
self, src: Union[str, TCounter[str]], tar: Union[str, TCounter[str]]
) -> '_TokenDistance':
"""Return the Q-Grams in src & tar.
- 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
Refactor this function to reduce its Cognitive Complexity from 21 to the 15 allowed. Open
def _soft_intersection(self) -> TCounter[str]:
- 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
Refactor this function to reduce its Cognitive Complexity from 46 to the 15 allowed. Open
def __init__(
- 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
Refactor this function to reduce its Cognitive Complexity from 121 to the 15 allowed. Open
def _group_linkage_intersection(self) -> TCounter[str]:
- 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
Too many local variables (18/15) Open
def _soft_intersection(self) -> TCounter[str]:
- Read upRead up
- Exclude checks
Used when a function or method has too many local variables.
Too many statements (80/50) Open
def _group_linkage_intersection(self) -> TCounter[str]:
- 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 (12/7) Open
class _TokenDistance(_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 nested blocks (6/5) Open
while step < 4:
- 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 local variables (23/15) Open
def _group_linkage_intersection(self) -> TCounter[str]:
- Read upRead up
- Exclude checks
Used when a function or method has too many local variables.
Too many branches (40/12) Open
def _group_linkage_intersection(self) -> TCounter[str]:
- Read upRead up
- Exclude checks
Used when a function or method has too many branches, making it hard to follow.
Too many statements (52/50) Open
def _soft_intersection(self) -> TCounter[str]:
- Read upRead up
- Exclude checks
Used when a function or method has too many statements. You should then split it in smaller functions / methods.
Unnecessary else
after break
Open
if not z_cols.size:
- Read upRead up
- Exclude checks
Used in order to highlight an unnecessary block of code following an if containing a break statement. As such, it will warn when it encounters an else following a chain of ifs, all of them containing a break statement.
Too many branches (20/12) Open
def __init__(
- Read upRead up
- Exclude checks
Used when a function or method has too many branches, making it hard to follow.
Too many statements (52/50) Open
def __init__(
- 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 nested blocks (6/5) Open
while step < 4:
- 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 elif
after return
Open
if self.params['alphabet'] is None:
- 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.
Merge this if statement with the enclosing one. Open
if (
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if condition1: if condition2: # ...
Compliant Solution
if condition1 and condition2: # ...
An attribute defined in abydos.distance._token_distance line 220 hides this method Open
def _intersection(self) -> TCounter[str]:
- Read upRead up
- Exclude checks
Used when a class defines a method which is hidden by an instance attribute from an ancestor class or set by some client code.
Unable to import 'numpy' Open
import numpy as np
- Read upRead up
- Exclude checks
Used when pylint has been unable to import a module.
String statement has no effect Open
"""
- Read upRead up
- Exclude checks
Used when a string is used as a statement (which of course has no effect). This is a particular case of W0104 with its own message so you can easily disable it if you're using those strings as documentation, instead of comments.
Attribute '_tar_orig' defined outside __init__ Open
self._tar_orig = tar
- Read upRead up
- Exclude checks
Used when an instance attribute is defined outside the init method.
Attribute '_src_orig' defined outside __init__ Open
self._src_orig = src
- Read upRead up
- Exclude checks
Used when an instance attribute is defined outside the init method.
Wrong hanging indentation before block (add 4 spaces). Open
self, src: Union[str, TCounter[str]], tar: Union[str, TCounter[str]]
- Read upRead up
- Exclude checks
TODO self, src: Union[str, TCounter[str]], tar: Union[str, TCounter[str]] ^ |
Unnecessary parens after 'not' keyword Open
if not (col_covered[col] | row_covered[row]):
- Read upRead up
- Exclude checks
Used when a single item in parentheses follows an if, for, or other keyword.
Wrong hanging indentation before block (add 4 spaces). Open
not (row_covered[row])
- Read upRead up
- Exclude checks
TODO not (row_covered[row]) ^ |
Argument name x
doesn't conform to snake_case naming style Open
def _norm_inverse(x: float, _squares: int, pop: float) -> float:
- 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,
- Read upRead up
- Exclude checks
TODO self, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
tokenizer: Optional[_Tokenizer] = None,
- Read upRead up
- Exclude checks
TODO tokenizer: Optional[_Tokenizer] = None, ^ |
Argument name x
doesn't conform to snake_case naming style Open
def _norm_none(x: float, _squares: int, _pop: float) -> float:
- 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
intersection_type: str = 'crisp',
- Read upRead up
- Exclude checks
TODO intersection_type: str = 'crisp', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
src: str, tar: str
- Read upRead up
- Exclude checks
TODO src: str, tar: str ^ |
Do not use len(SEQUENCE)
without comparison to determine if a sequence is empty Open
if not len(self._soft_intersection_precalc):
- Read upRead up
- Exclude checks
Used when Pylint detects that len(sequence) is being used without explicit comparison inside a condition to determine if a sequence is empty. Instead of coercing the length to a boolean, either rely on the fact that empty sequences are false or compare the length against a scalar.
Wrong hanging indentation before block (add 4 spaces). Open
'normalizer' in self.params
- Read upRead up
- Exclude checks
TODO 'normalizer' in self.params ^ |
Wrong hanging indentation before block (add 4 spaces). Open
np.count_nonzero(starred[row, :]) == 0
- Read upRead up
- Exclude checks
TODO np.count_nonzero(starred[row, :]) == 0 ^ |
Do not use len(SEQUENCE)
without comparison to determine if a sequence is empty Open
if not len(self._soft_intersection_precalc):
- Read upRead up
- Exclude checks
Used when Pylint detects that len(sequence) is being used without explicit comparison inside a condition to determine if a sequence is empty. Instead of coercing the length to a boolean, either rely on the fact that empty sequences are false or compare the length against a scalar.
Consider using enumerate instead of iterating with range and len Open
for row in range(len(tar_only_tok)):
- Read upRead up
- Exclude checks
Emitted when code that iterates with range and len is encountered. Such code can be simplified by using the enumerate builtin.
Wrong hanging indentation before block (add 4 spaces). Open
**kwargs: Any
- Read upRead up
- Exclude checks
TODO **kwargs: Any ^ |
Do not use len(SEQUENCE)
without comparison to determine if a sequence is empty Open
if not len(self._soft_intersection_precalc):
- Read upRead up
- Exclude checks
Used when Pylint detects that len(sequence) is being used without explicit comparison inside a condition to determine if a sequence is empty. Instead of coercing the length to a boolean, either rely on the fact that empty sequences are false or compare the length against a scalar.
Unnecessary parens after 'not' keyword Open
if not (col_covered[col] | row_covered[row]):
- Read upRead up
- Exclude checks
Used when a single item in parentheses follows an if, for, or other keyword.
Argument name x
doesn't conform to snake_case naming style Open
def _norm_complement(x: float, _squares: int, pop: float) -> float:
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Variable name n
doesn't conform to snake_case naming style Open
n = max(len(src_only_tok), len(tar_only_tok))
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Unnecessary parens after 'not' keyword Open
if not (col_covered[col]):
- Read upRead up
- Exclude checks
Used when a single item in parentheses follows an if, for, or other keyword.
Argument name x
doesn't conform to snake_case naming style Open
def _norm_laplace(x: float, squares: int, _pop: float) -> float:
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Do not use len(SEQUENCE)
without comparison to determine if a sequence is empty Open
if not len(self._soft_intersection_precalc):
- Read upRead up
- Exclude checks
Used when Pylint detects that len(sequence) is being used without explicit comparison inside a condition to determine if a sequence is empty. Instead of coercing the length to a boolean, either rely on the fact that empty sequences are false or compare the length against a scalar.
Wrong hanging indentation before block (add 4 spaces). Open
self.params['alphabet'], Counter
- Read upRead up
- Exclude checks
TODO self.params['alphabet'], Counter ^ |
Do not use len(SEQUENCE)
without comparison to determine if a sequence is empty Open
if not len(self._soft_intersection_precalc):
- Read upRead up
- Exclude checks
Used when Pylint detects that len(sequence) is being used without explicit comparison inside a condition to determine if a sequence is empty. Instead of coercing the length to a boolean, either rely on the fact that empty sequences are false or compare the length against a scalar.
Consider using enumerate instead of iterating with range and len Open
for col in range(len(src_only_tok)):
- Read upRead up
- Exclude checks
Emitted when code that iterates with range and len is encountered. Such code can be simplified by using the enumerate builtin.
Wrong hanging indentation before block (add 4 spaces). Open
row_covered[row] | col_covered[col]
- Read upRead up
- Exclude checks
TODO rowcovered[row] | colcovered[col] ^ |
Argument name x
doesn't conform to snake_case naming style Open
def _norm_proportional(x: float, _squares: int, pop: float) -> float:
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Argument name x
doesn't conform to snake_case naming style Open
def _norm_exp(x: float, _squares: int, _pop: float) -> float:
- 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 self.params['normalizer'] in self._norm_dict
- Read upRead up
- Exclude checks
TODO and self.params['normalizer'] in self.normdict ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and np.count_nonzero(starred[:, col]) == 0
- Read upRead up
- Exclude checks
TODO and np.count_nonzero(starred[:, col]) == 0 ^ |
Unnecessary parens after 'not' keyword Open
if not (col_covered[col]):
- Read upRead up
- Exclude checks
Used when a single item in parentheses follows an if, for, or other keyword.
Argument name x
doesn't conform to snake_case naming style Open
def _norm_log(x: float, _squares: int, _pop: float) -> float:
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Do not use len(SEQUENCE)
without comparison to determine if a sequence is empty Open
if not len(self._soft_intersection_precalc):
- Read upRead up
- Exclude checks
Used when Pylint detects that len(sequence) is being used without explicit comparison inside a condition to determine if a sequence is empty. Instead of coercing the length to a boolean, either rely on the fact that empty sequences are false or compare the length against a scalar.
Consider using enumerate instead of iterating with range and len Open
for i in range(len(_src)):
- Read upRead up
- Exclude checks
Emitted when code that iterates with range and len is encountered. Such code can be simplified by using the enumerate builtin.
Wrong hanging indentation before block (add 4 spaces). Open
and arr[row, col] < h_val
- Read upRead up
- Exclude checks
TODO and arr[row, col] < h_val ^ |
Wrong hanging indentation before block (add 4 spaces). Open
self.params['tokenizer'], (QGrams, QSkipgrams)
- Read upRead up
- Exclude checks
TODO self.params['tokenizer'], (QGrams, QSkipgrams) ^ |
Do not use len(SEQUENCE)
without comparison to determine if a sequence is empty Open
if not len(self._soft_intersection_precalc):
- Read upRead up
- Exclude checks
Used when Pylint detects that len(sequence) is being used without explicit comparison inside a condition to determine if a sequence is empty. Instead of coercing the length to a boolean, either rely on the fact that empty sequences are false or compare the length against a scalar.