Function encode
has a Cognitive Complexity of 480 (exceeds 5 allowed). Consider refactoring. Open
def encode(self, word: str) -> str:
"""Return the phonet code for a word.
Parameters
----------
- 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 _phonet.py
has 1551 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
Consider simplifying this complex logical expression. Open
if (
not rule
or (
(rule[0] == '^')
and ((i == 0) or not src[i - 1].isalpha())
Consider simplifying this complex logical expression. Open
if pos >= 0:
# check rules for this char
while (_phonet_rules[pos] is None) or (
cast(str, _phonet_rules[pos])[0] == char
):
Avoid deeply nested control flow statements. Open
if pos0 >= 0:
while (_phonet_rules[pos0] is None) or (
cast(str, _phonet_rules[pos0])[0] == char0
):
if pos0 > end3:
Avoid deeply nested control flow statements. Open
if (priority0 == 1) and (zeta == 0):
# rule with '<' is applied
if (
(j > 0)
and rule
Avoid deeply nested control flow statements. Open
if (
(len(src) > (i + matches))
and src[i + matches].isalpha()
and (src[i + matches] in rule[1:])
):
Avoid deeply nested control flow statements. Open
if _phonet_rules[pos] and (
'<' in cast(str, _phonet_rules[pos])[1:]
):
priority0 = 1
else:
Avoid deeply nested control flow statements. Open
if k <= 0:
# add hash value for all letters
if phonet_hash_1[j, 0] < 0:
phonet_hash_1[j, 0] = i
Avoid deeply nested control flow statements. Open
if (
(matches > 1)
and src[i + matches : i + matches + 1]
and (priority0 != ord('-'))
):
Avoid deeply nested control flow statements. Open
if k > 0:
# add hash value for this letter
if phonet_hash_1[j, k] < 0:
phonet_hash_1[j, k] = i
phonet_hash_2[j, k] = i
Avoid deeply nested control flow statements. Open
if start2 > 0:
pos = start2
start1 = start2
start2 = -1
end1 = end2
Consider simplifying this complex logical expression. Open
if pos0 >= 0:
while (_phonet_rules[pos0] is None) or (
cast(str, _phonet_rules[pos0])[0] == char0
):
if pos0 > end3:
Refactor this function to reduce its Cognitive Complexity from 485 to the 15 allowed. Open
def encode(self, word: 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
Consider using tuple unpacking for swapping variables Open
pos = end1
- Read upRead up
- Exclude checks
You do not have to use a temporary variable in order to swap variables. Using tuple unpacking
to directly swap variables makes the intention more clear.
Too many nested blocks (7/5) Open
while i < len(src):
- 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 nested blocks (9/5) Open
while i < len(src):
- 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 branches (20/12) Open
def _initialize_phonet(lang: str) -> None:
- 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
while i < len(src):
- 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 nested blocks (8/5) Open
while i < len(src):
- 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 nested blocks (6/5) Open
while i < len(src):
- 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 branches (65/12) Open
def _phonet(term: str, mode: int, lang: str) -> str:
- Read upRead up
- Exclude checks
Used when a function or method has too many branches, making it hard to follow.
Consider using tuple unpacking for swapping variables Open
pos = start1
- Read upRead up
- Exclude checks
You do not have to use a temporary variable in order to swap variables. Using tuple unpacking
to directly swap variables makes the intention more clear.
Simplify chained comparison between the operands Open
if (end3 >= start4) and (start4 >= 0):
- Read upRead up
- Exclude checks
This message is emitted when pylint encounters boolean operation likea < b and b < c
, suggesting instead to refactor it to a < b < c
Too many statements (210/50) Open
def _phonet(term: str, mode: int, lang: str) -> 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.
Simplify chained comparison between the operands Open
if (end1 >= start2) and (start2 >= 0):
- Read upRead up
- Exclude checks
This message is emitted when pylint encounters boolean operation likea < b and b < c
, suggesting instead to refactor it to a < b < c
Too many nested blocks (8/5) Open
while i < len(src):
- 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 (256/50) Open
def encode(self, word: str) -> 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 boolean expressions in if statement (12/5) Open
not rule
- Read upRead up
- Exclude checks
Used when an if statement contains too many boolean expressions.
Too many nested blocks (7/5) Open
while i < len(src):
- 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 nested blocks (6/5) Open
for i in range(len(_phonet_rules)):
- 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 nested blocks (8/5) Open
while i < len(src):
- 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 (29/15) Open
def _phonet(term: str, mode: int, lang: str) -> str:
- Read upRead up
- Exclude checks
Used when a function or method has too many local variables.
Consider using tuple unpacking for swapping variables Open
pos0 = end3
- Read upRead up
- Exclude checks
You do not have to use a temporary variable in order to swap variables. Using tuple unpacking
to directly swap variables makes the intention more clear.
Too many nested blocks (6/5) Open
for i in range(len(_phonet_rules)):
- 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.
Consider using tuple unpacking for swapping variables Open
pos0 = start3
- Read upRead up
- Exclude checks
You do not have to use a temporary variable in order to swap variables. Using tuple unpacking
to directly swap variables makes the intention more clear.
Merge this if statement with the enclosing one. Open
if src[
- 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: # ...
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: # ...
Unused Counter imported from typing as TCounter Open
from typing import Counter as TCounter, Optional, Tuple, Union, cast
- Read upRead up
- Exclude checks
Used when an imported module or variable is not used.
Wrong hanging indentation before block (add 4 spaces). Open
'É',
- Read upRead up
- Exclude checks
TODO 'É', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Õ',
- Read upRead up
- Exclude checks
TODO 'Õ', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ã',
- Read upRead up
- Exclude checks
TODO 'Ã', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ç',
- Read upRead up
- Exclude checks
TODO 'Ç', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
rule
- Read upRead up
- Exclude checks
TODO rule ^ |
Wrong hanging indentation before block (add 4 spaces). Open
or (
- Read upRead up
- Exclude checks
TODO or ( ^ |
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
and '^^'
- Read upRead up
- Exclude checks
TODO and '^^' ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ü',
- Read upRead up
- Exclude checks
TODO 'Ü', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
cast(str, _phonet_rules[pos])[0] == char
- Read upRead up
- Exclude checks
TODO cast(str, phonetrules[pos])[0] == char ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and (src[i + matches] == rule[0])
- Read upRead up
- Exclude checks
TODO and (src[i + matches] == rule[0]) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
not rule
- Read upRead up
- Exclude checks
TODO not rule ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Á',
- Read upRead up
- Exclude checks
TODO 'Á', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'È',
- Read upRead up
- Exclude checks
TODO 'È', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
or (
- Read upRead up
- Exclude checks
TODO or ( ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and (priority0 != ord('-'))
- Read upRead up
- Exclude checks
TODO and (priority0 != ord('-')) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ù',
- Read upRead up
- Exclude checks
TODO 'Ù', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Š',
- Read upRead up
- Exclude checks
TODO 'Š', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ë',
- Read upRead up
- Exclude checks
TODO 'Ë', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
(matches > 1)
- Read upRead up
- Exclude checks
TODO (matches > 1) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ó',
- Read upRead up
- Exclude checks
TODO 'Ó', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
i + matches0 : i + matches0 + 1
- Read upRead up
- Exclude checks
TODO i + matches0 : i + matches0 + 1 ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and (
- Read upRead up
- Exclude checks
TODO and ( ^ |
Wrong hanging indentation before block (add 4 spaces). Open
# rule == '^' is not possible here
- Read upRead up
- Exclude checks
TODO # rule == '^' is not possible here ^ |
Variable name ch
doesn't conform to snake_case naming style Open
for ch in {
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Variable name ch
doesn't conform to snake_case naming style Open
for i, ch in enumerate('ABCDEFGHIJKLMNOPQRSTUVWXYZ'):
- 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
'Ú',
- Read upRead up
- Exclude checks
TODO 'Ú', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Œ',
- Read upRead up
- Exclude checks
TODO 'Œ', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Â',
- Read upRead up
- Exclude checks
TODO 'Â', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Æ',
- Read upRead up
- Exclude checks
TODO 'Æ', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Î',
- Read upRead up
- Exclude checks
TODO 'Î', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ð',
- Read upRead up
- Exclude checks
TODO 'Ð', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
or cast(str, _phonet_rules[i + 2])
- Read upRead up
- Exclude checks
TODO or cast(str, phonetrules[i + 2]) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
_phonet_rules[pos + mode] is None
- Read upRead up
- Exclude checks
TODO phonetrules[pos + mode] is None ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and (
- Read upRead up
- Exclude checks
TODO and ( ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Û',
- Read upRead up
- Exclude checks
TODO 'Û', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'ß',
- Read upRead up
- Exclude checks
TODO 'ß', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and rule
- Read upRead up
- Exclude checks
TODO and rule ^ |
Wrong hanging indentation before block (add 4 spaces). Open
_phonet_rules[pos]
- Read upRead up
- Exclude checks
TODO phonetrules[pos] ^ |
Consider using enumerate instead of iterating with range and len Open
for i in range(len(_phonet_rules)):
- 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
'Ò',
- Read upRead up
- Exclude checks
TODO 'Ò', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ÿ',
- Read upRead up
- Exclude checks
TODO 'Ÿ', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and (len(src) > (i + matches))
- Read upRead up
- Exclude checks
TODO and (len(src) > (i + matches)) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
not rule
- Read upRead up
- Exclude checks
TODO not rule ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and (
- Read upRead up
- Exclude checks
TODO and ( ^ |
Variable name ch
doesn't conform to snake_case naming style Open
ch = cast(str, _phonet_rules[i])[0]
- 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
'Ï',
- Read upRead up
- Exclude checks
TODO 'Ï', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ô',
- Read upRead up
- Exclude checks
TODO 'Ô', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and not rule[0].isdigit()
- Read upRead up
- Exclude checks
TODO and not rule[0].isdigit() ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and src[i + matches].isalpha()
- Read upRead up
- Exclude checks
TODO and src[i + matches].isalpha() ^ |
Wrong hanging indentation before block (add 4 spaces). Open
cast(str, _phonet_rules[pos0])[0] == char0
- Read upRead up
- Exclude checks
TODO cast(str, phonetrules[pos0])[0] == char0 ^ |
Wrong hanging indentation before block (add 4 spaces). Open
_phonet_rules[pos0 + mode] is None
- Read upRead up
- Exclude checks
TODO phonetrules[pos0 + mode] is None ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ý',
- Read upRead up
- Exclude checks
TODO 'Ý', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ä',
- Read upRead up
- Exclude checks
TODO 'Ä', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Í',
- Read upRead up
- Exclude checks
TODO 'Í', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ö',
- Read upRead up
- Exclude checks
TODO 'Ö', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ø',
- Read upRead up
- Exclude checks
TODO 'Ø', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Þ',
- Read upRead up
- Exclude checks
TODO 'Þ', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and (rule not in '(-<^$')
- Read upRead up
- Exclude checks
TODO and (rule not in '(-<^$') ^ |
Wrong hanging indentation before block (add 4 spaces). Open
cast(str, _phonet_rules[i + 1])
- Read upRead up
- Exclude checks
TODO cast(str, phonetrules[i + 1]) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
or (
- Read upRead up
- Exclude checks
TODO or ( ^ |
Wrong hanging indentation before block (add 4 spaces). Open
(len(src) > (i + matches))
- Read upRead up
- Exclude checks
TODO (len(src) > (i + matches)) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
in cast(str, _phonet_rules[pos])[1:]
- Read upRead up
- Exclude checks
TODO in cast(str, phonetrules[pos])[1:] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
(start3 < 0) or (start4 < start3)
- Read upRead up
- Exclude checks
TODO (start3 < 0) or (start4 < start3) ^ |
Too many lines in module (1745/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 src[i + matches : i + matches + 1]
- Read upRead up
- Exclude checks
TODO and src[i + matches : i + matches + 1] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
rule
- Read upRead up
- Exclude checks
TODO rule ^ |
Wrong hanging indentation before block (add 4 spaces). Open
(_phonet_rules[pos0] is not None)
- Read upRead up
- Exclude checks
TODO (phonetrules[pos0] is not None) ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Å',
- Read upRead up
- Exclude checks
TODO 'Å', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and (
- Read upRead up
- Exclude checks
TODO and ( ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ê',
- Read upRead up
- Exclude checks
TODO 'Ê', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ñ',
- Read upRead up
- Exclude checks
TODO 'Ñ', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'<' in cast(str, _phonet_rules[pos])[1:]
- Read upRead up
- Exclude checks
TODO '<' in cast(str, phonetrules[pos])[1:] ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'À',
- Read upRead up
- Exclude checks
TODO 'À', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
'Ì',
- Read upRead up
- Exclude checks
TODO 'Ì', ^ |
Wrong hanging indentation before block (add 4 spaces). Open
and (src[i + matches] in rule[1:])
- Read upRead up
- Exclude checks
TODO and (src[i + matches] in rule[1:]) ^ |