Function download_package
has a Cognitive Complexity of 43 (exceeds 5 allowed). Consider refactoring. Open
def download_package(
resource_name: str,
url: Optional[str] = None,
data_path: Optional[str] = None,
force: bool = False,
- 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 download_package. (15) Open
def download_package(
resource_name: str,
url: Optional[str] = None,
data_path: Optional[str] = None,
force: bool = False,
- 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 list_available_packages. (10) Open
def list_available_packages(
url: Optional[str] = None,
) -> Tuple[
List[Tuple[str, str, float, str, str, str]],
List[Tuple[str, str, List[str]]],
- 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 list_installed_packages
has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring. Open
def list_installed_packages(
path: Optional[str] = None,
) -> List[Tuple[str, str, float]]:
"""List all installed data packages."""
if path:
- 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 list_installed_packages. (8) Open
def list_installed_packages(
path: Optional[str] = None,
) -> List[Tuple[str, str, float]]:
"""List all installed data packages."""
if path:
- 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 _default_download_dir. (8) Open
def _default_download_dir() -> Optional[str]:
"""Return the directory to which packages will be downloaded by default.
This is mostly copied from NLTK's
nltk.downloader.Downloader.default_download_dir
- 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 _default_download_dir
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
def _default_download_dir() -> Optional[str]:
"""Return the directory to which packages will be downloaded by default.
This is mostly copied from NLTK's
nltk.downloader.Downloader.default_download_dir
- 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 os.path.isdir(os.path.join(check_path, package)):
with open(
os.path.join(check_path, package + '.xml')
) as xml:
file = xml.read()
Avoid deeply nested control flow statements. Open
for inst in installed: # pragma: no branch
if pack[0] == inst[0] and pack[2] <= inst[2]:
if not silent:
print( # pragma: no cover # noqa: T001
'{} package already up-to-date'.format(
Function download_package
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
def download_package(
Function package_path
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
def package_path(resource_name: str) -> str:
"""Given a resource name, returns the path to the package."""
for path in data_path:
for subdir in DATA_SUBDIRS:
check_path = os.path.join(path, subdir, resource_name)
- 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 43 to the 15 allowed. Open
def download_package(
- 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 17 to the 15 allowed. Open
def list_installed_packages(
- 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 nested blocks (7/5) Open
for coll in collections:
- 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 (13/12) Open
def download_package(
- Read upRead up
- Exclude checks
Used when a function or method has too many branches, making it hard to follow.
Redefining argument with the local name 'resource_name' Open
for resource_name in coll[2]:
- Read upRead up
- Exclude checks
Used when a local name is redefining an argument, which might suggest a potential error. This is taken in account only for a handful of name binding operations, such as for iteration, with statement assignment and exception handler assignment.
Redefining argument with the local name 'path' Open
for path in paths:
- Read upRead up
- Exclude checks
Used when a local name is redefining an argument, which might suggest a potential error. This is taken in account only for a handful of name binding operations, such as for iteration, with statement assignment and exception handler assignment.
Else clause on loop without a break statement Open
else:
- Read upRead up
- Exclude checks
Loops should only have an else clause if they can exit early with a break statement, otherwise the statements under else should be on the same scope as the loop itself.
Redefining name 'data_path' from outer scope (line 52) Open
data_path: Optional[str] = None,
- Read upRead up
- Exclude checks
Used when a variable's name hides a name defined in the outer scope.
Wrong hanging indentation before block (add 4 spaces). Open
silent: bool = False,
- Read upRead up
- Exclude checks
TODO silent: bool = False, ^ |
Constant name data_path
doesn't conform to UPPER_CASE naming style Open
data_path = [] # type: List[str]
- 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
path: Optional[str] = None,
- Read upRead up
- Exclude checks
TODO path: Optional[str] = None, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
resource_name: str,
- Read upRead up
- Exclude checks
TODO resource_name: str, ^ |
Constant name _paths_from_env
doesn't conform to UPPER_CASE naming style Open
_paths_from_env = os.environ.get('ABYDOS_DATA', str('')).split(
- 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
abydos_data, os.W_OK
- Read upRead up
- Exclude checks
TODO abydosdata, os.WOK ^ |
Wrong hanging indentation before block (add 4 spaces). Open
url: Optional[str] = None,
- Read upRead up
- Exclude checks
TODO url: Optional[str] = None, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
os.path.join(check_path, package + '.xml')
- Read upRead up
- Exclude checks
TODO os.path.join(check_path, package + '.xml') ^ |
Variable name ix
doesn't conform to snake_case naming style Open
with urllib.request.urlopen(url) as ix: # noqa: S310
- 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
url: Optional[str] = None,
- Read upRead up
- Exclude checks
TODO url: Optional[str] = None, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
data_path: Optional[str] = None,
- Read upRead up
- Exclude checks
TODO data_path: Optional[str] = None, ^ |
Wrong hanging indentation before block (add 4 spaces). Open
force: bool = False,
- Read upRead up
- Exclude checks
TODO force: bool = False, ^ |