File _phones.py
has 910 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
Cyclomatic complexity is too high in function cmp_features. (16) Open
def cmp_features(
feat1: int,
feat2: int,
weights: Optional[
Union[Sequence[Union[int, float]], Dict[str, Union[int, 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 cmp_features
has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring. Open
def cmp_features(
feat1: int,
feat2: int,
weights: Optional[
Union[Sequence[Union[int, float]], Dict[str, Union[int, 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 ipa_to_feature_dicts
has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring. Open
def ipa_to_feature_dicts(ipa: str) -> List[Dict[str, str]]:
"""Convert IPA to a feature dict list.
This translates an IPA string of one or more phones to a list of dicts
representing the features of the string.
- 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 function ipa_to_feature_dicts. (11) Open
def ipa_to_feature_dicts(ipa: str) -> List[Dict[str, str]]:
"""Convert IPA to a feature dict list.
This translates an IPA string of one or more phones to a list of dicts
representing the features of the string.
- 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 function get_feature. (7) Open
def get_feature(vector: List[int], feature: str) -> List[Union[int, float]]:
"""Get a feature vector.
This returns a list of ints, equal in length to the vector input,
representing presence/absence/neutrality with respect to a particular
- 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 function ipa_to_features. (7) Open
def ipa_to_features(ipa: str) -> List[int]:
"""Convert IPA to features.
This translates an IPA string of one or more phones to a list of ints
representing the features of the string.
- 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 get_feature
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
def get_feature(vector: List[int], feature: str) -> List[Union[int, float]]:
"""Get a feature vector.
This returns a list of ints, equal in length to the vector input,
representing presence/absence/neutrality with respect to a particular
- 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 ipa_to_features
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def ipa_to_features(ipa: str) -> List[int]:
"""Convert IPA to features.
This translates an IPA string of one or more phones to a list of ints
representing the features of the string.
- 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 masked == 0:
feature_dict[feature] = '0' # 0
elif masked == mask:
feature_dict[feature] = '+/-' # +/-
elif masked & pos_mask:
Refactor this function to reduce its Cognitive Complexity from 24 to the 15 allowed. Open
def cmp_features(
- 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 21 to the 15 allowed. Open
def ipa_to_feature_dicts(ipa: str) -> List[Dict[str, 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
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.
Wrong hanging indentation before block (add 4 spaces). Open
feat1: int,
- Read upRead up
- Exclude checks
TODO feat1: int, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
pos + i - 1 <= len(ipa)
- Read upRead up
- Exclude checks
TODO pos + i - 1 <= len(ipa) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
weights: Optional[
- Read upRead up
- Exclude checks
TODO weights: Optional[ ^ |
Wrong hanging indentation before block (add 4 spaces). Open
pos + i - 1 <= len(ipa)
- Read upRead up
- Exclude checks
TODO pos + i - 1 <= len(ipa) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
feat2: int,
- Read upRead up
- Exclude checks
TODO feat2: int, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and ipa[pos : pos + i] in _PHONETIC_FEATURES
- Read upRead up
- Exclude checks
TODO and ipa[pos : pos + i] in PHONETICFEATURES ^ |
Too many lines in module (1006/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
and ipa[pos : pos + i] in _PHONETIC_FEATURES
- Read upRead up
- Exclude checks
TODO and ipa[pos : pos + i] in PHONETICFEATURES ^ |
Consider iterating the dictionary directly instead of calling .keys() Open
for feature in _FEATURE_MASK.keys():
- Read upRead up
- Exclude checks
Emitted when the keys of a dictionary are iterated through the .keys() method. It is enough to just iterate through the dictionary itself, as in for key in dictionary
.