Cyclomatic complexity is too high in method create_records. (8) Open
def create_records(self, msg_text):
'''
Given the text from a message, create a list of record objects and
return that list.
'''
- 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 create_records
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
def create_records(self, msg_text):
'''
Given the text from a message, create a list of record objects and
return that list.
'''
- 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
Method could be a function Open
def _create_record_objects(self, msg_text, record_class):
- Read upRead up
- Exclude checks
Used when a method doesn't use its bound instance, and so could be written as a function.
Method could be a function Open
def _create_stars(self, msg_text):
- Read upRead up
- Exclude checks
Used when a method doesn't use its bound instance, and so could be written as a function.
Too few public methods (1/2) Open
class RecordFactory(object):
- Read upRead up
- Exclude checks
Used when class has too few public methods, so be sure it's really worth it.
Class 'RecordFactory' inherits from object, can be safely removed from bases in python3 Open
class RecordFactory(object):
- Read upRead up
- Exclude checks
Used when a class inherit from object, which under python3 is implicit, hence can be safely removed from bases.
Method could be a function Open
def _create_cars(self, msg_text):
- Read upRead up
- Exclude checks
Used when a method doesn't use its bound instance, and so could be written as a function.
Method could be a function Open
def _create_aurs(self, msg_text):
- Read upRead up
- Exclude checks
Used when a method doesn't use its bound instance, and so could be written as a function.
Cannot import 'apel.db.loader.aur_parser' due to syntax error 'invalid syntax (<unknown>, line 131)'</unknown> Open
from apel.db.loader.aur_parser import AurParser
- Read upRead up
- Exclude checks
Used when a syntax error is raised for a module.
No name 'car_parser' in module 'apel.db.loader' Open
from apel.db.loader.car_parser import CarParser
- Read upRead up
- Exclude checks
Used when a name cannot be found in a module.
Cannot import 'apel.db.loader.car_parser' due to syntax error 'invalid syntax (<unknown>, line 160)'</unknown> Open
from apel.db.loader.car_parser import CarParser
- Read upRead up
- Exclude checks
Used when a syntax error is raised for a module.
No name 'star_parser' in module 'apel.db.loader' Open
from apel.db.loader.star_parser import StarParser
- Read upRead up
- Exclude checks
Used when a name cannot be found in a module.
Unnecessary pass statement Open
pass
- Read upRead up
- Exclude checks
Used when a pass
statement that can be avoided is encountered.
No name 'aur_parser' in module 'apel.db.loader' Open
from apel.db.loader.aur_parser import AurParser
- Read upRead up
- Exclude checks
Used when a name cannot be found in a module.
Cannot import 'apel.db.loader.star_parser' due to syntax error 'invalid syntax (<unknown>, line 139)'</unknown> Open
from apel.db.loader.star_parser import StarParser
- Read upRead up
- Exclude checks
Used when a syntax error is raised for a module.
Remove this commented out code. Open
# msg_header_version = header[index:].strip()
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
See
- MISRA C:2004, 2.4 - Sections of code should not be "commented out".
- MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
- MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
- MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
Remove this commented out code. Open
# created_records = self._create_aurs(msg_text)
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
See
- MISRA C:2004, 2.4 - Sections of code should not be "commented out".
- MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
- MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
- MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
Line too long (84 > 79 characters) Open
"""Given the text from a record message, return a list of record objects."""
- Read upRead up
- Exclude checks
Limit all lines to a maximum of 79 characters.
There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to
have several windows side-by-side. The default wrapping on such
devices looks ugly. Therefore, please limit all lines to a maximum
of 79 characters. For flowing long blocks of text (docstrings or
comments), limiting the length to 72 characters is recommended.
Reports error E501.
Expected 2 blank lines, found 1 Open
class RecordFactoryException(Exception):
- Read upRead up
- Exclude checks
Separate top-level function and class definitions with two blank lines.
Method definitions inside a class are separated by a single blank
line.
Extra blank lines may be used (sparingly) to separate groups of
related functions. Blank lines may be omitted between a bunch of
related one-liners (e.g. a set of dummy implementations).
Use blank lines in functions, sparingly, to indicate logical
sections.
Okay: def a():\n pass\n\n\ndef b():\n pass
Okay: def a():\n pass\n\n\nasync def b():\n pass
Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass
Okay: default = 1\nfoo = 1
Okay: classify = 1\nfoo = 1
E301: class Foo:\n b = 0\n def bar():\n pass
E302: def a():\n pass\n\ndef b(n):\n pass
E302: def a():\n pass\n\nasync def b(n):\n pass
E303: def a():\n pass\n\n\n\ndef b(n):\n pass
E303: def a():\n\n\n\n pass
E304: @decorator\n\ndef a():\n pass
E305: def a():\n pass\na()
E306: def a():\n def b():\n pass\n def c():\n pass
Line too long (94 > 79 characters) Open
raise RecordFactoryException('Aggregated usage record not yet supported.')
- Read upRead up
- Exclude checks
Limit all lines to a maximum of 79 characters.
There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to
have several windows side-by-side. The default wrapping on such
devices looks ugly. Therefore, please limit all lines to a maximum
of 79 characters. For flowing long blocks of text (docstrings or
comments), limiting the length to 72 characters is recommended.
Reports error E501.
Line too long (95 > 79 characters) Wontfix
# Use the full header to distinguish normalised and non-norm summaries.
- Read upRead up
- Exclude checks
Limit all lines to a maximum of 79 characters.
There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to
have several windows side-by-side. The default wrapping on such
devices looks ugly. Therefore, please limit all lines to a maximum
of 79 characters. For flowing long blocks of text (docstrings or
comments), limiting the length to 72 characters is recommended.
Reports error E501.
Line too long (84 > 79 characters) Wontfix
created_records = self._create_record_objects(msg_text, record_type)
- Read upRead up
- Exclude checks
Limit all lines to a maximum of 79 characters.
There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to
have several windows side-by-side. The default wrapping on such
devices looks ugly. Therefore, please limit all lines to a maximum
of 79 characters. For flowing long blocks of text (docstrings or
comments), limiting the length to 72 characters is recommended.
Reports error E501.
Line too long (96 > 79 characters) Wontfix
raise RecordFactoryException('Message type %s not recognised.' % header)
- Read upRead up
- Exclude checks
Limit all lines to a maximum of 79 characters.
There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to
have several windows side-by-side. The default wrapping on such
devices looks ugly. Therefore, please limit all lines to a maximum
of 79 characters. For flowing long blocks of text (docstrings or
comments), limiting the length to 72 characters is recommended.
Reports error E501.
Variable name e
doesn't conform to snake_case naming style Open
except ValueError as e:
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
Constant name log
doesn't conform to UPPER_CASE naming style Open
log = logging.getLogger(__name__)
- Read upRead up
- Exclude checks
Used when the name doesn't conform to naming rules associated to its type (constant, variable, class...).
standard import import logging
should be placed before from apel.db.records.job import JobRecord
Open
import logging
- Read upRead up
- Exclude checks
Used when PEP8 import order is not respected (standard imports first, then third-party libraries, then local imports)