File _confusion_table.py
has 1528 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
ConfusionTable
has 69 functions (exceeds 20 allowed). Consider refactoring. Open
class ConfusionTable:
"""ConfusionTable object.
This object is initialized by passing either four integers (or a tuple of
four integers) representing the squares of a confusion table:
Cyclomatic complexity is too high in method __eq__. (17) Open
def __eq__(self, other: object) -> bool:
"""Perform eqality (==) comparison.
Compares a ConfusionTable to another ConfusionTable or its equivalent
in the form of a tuple, list, or dict.
- 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 __init__. (8) Open
def __init__(
self,
tp: Union[
float,
Tuple[float, float, float, float],
- 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 14 (exceeds 5 allowed). Consider refactoring. Open
def __init__(
self,
tp: Union[
float,
Tuple[float, float, float, float],
- 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 __eq__
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
def __eq__(self, other: object) -> bool:
"""Perform eqality (==) comparison.
Compares a ConfusionTable to another ConfusionTable or its equivalent
in the form of a tuple, list, or dict.
- 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 too many return
statements within this function. Open
return False
Unnecessary elif
after return
Open
if not precision or not recall:
- 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 public methods (65/20) Open
class ConfusionTable:
- Read upRead up
- Exclude checks
Used when class has too many public methods, try to reduce this to get a simpler (and so easier to use) class.
Remove those useless parentheses. Open
for _ in (
- Read upRead up
- Exclude checks
The use of parentheses, even those not required to enforce a desired order of operations, can clarify the intent behind a piece of code. But redundant pairs of parentheses could be misleading, and should be removed.
Noncompliant Code Example
return ((3)) # Noncompliant return ((x + 1)) # Noncompliant x = ((y / 2)) + 1 # Noncompliant
Compliant Solution
return 3 return (3) return x + 1 return (x + 1) x = y / 2 + 1 x = (y / 2) + 1
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: # ...
Wrong hanging indentation before block (add 4 spaces). Open
self._tp == other.true_pos()
- Read upRead up
- Exclude checks
TODO self.tp == other.truepos() ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._fn == other[3]
- Read upRead up
- Exclude checks
TODO and self._fn == other[3] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
self._tp == other['tp']
- Read upRead up
- Exclude checks
TODO self._tp == other['tp'] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._fp == other.false_pos()
- Read upRead up
- Exclude checks
TODO and self.fp == other.falsepos() ^ |
Too many lines in module (2176/1000) Open
# Copyright 2014-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
tp: Union[
- Read upRead up
- Exclude checks
TODO tp: Union[ ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._tn == other['tn']
- Read upRead up
- Exclude checks
TODO and self._tn == other['tn'] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._fn == other['fn']
- Read upRead up
- Exclude checks
TODO and self._fn == other['fn'] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
fp: float = 0.0,
- Read upRead up
- Exclude checks
TODO fp: float = 0.0, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
tn: float = 0.0,
- Read upRead up
- Exclude checks
TODO tn: float = 0.0, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._fp == other['fp']
- Read upRead up
- Exclude checks
TODO and self._fp == other['fp'] ^ |
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
and self._fn == other.false_neg()
- Read upRead up
- Exclude checks
TODO and self.fn == other.falseneg() ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._fp == other[2]
- Read upRead up
- Exclude checks
TODO and self._fp == other[2] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
self._tp == other[0]
- Read upRead up
- Exclude checks
TODO self._tp == other[0] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._tn == other[1]
- Read upRead up
- Exclude checks
TODO and self._tn == other[1] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
fn: float = 0.0,
- Read upRead up
- Exclude checks
TODO fn: float = 0.0, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and self._tn == other.true_neg()
- Read upRead up
- Exclude checks
TODO and self.tn == other.trueneg() ^ |