auxilium/tools/docmaintain_tools.py
Function replace_headers
has a Cognitive Complexity of 41 (exceeds 5 allowed). Consider refactoring. Open
Open
def replace_headers(pkg=basename(getcwd()), last=None, path=getcwd()):
last = dict() if last is None else last
pkg = __import__(pkg) if isinstance(pkg, str) else pkg
root, _ = split(pkg.__file__)
- 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
Open
if lines:
new_lines = new_header + ['', ''] + lines
else:
new_lines = new_header
Avoid deeply nested control flow statements. Open
Open
if removed and removed[0].startswith('#!'):
new_header[0] = removed[0]
# add new header
if lines:
Avoid deeply nested control flow statements. Open
Open
if last.get(file, '') == str(getmtime(file)):
this[file] = str(getmtime(file))
log(LEVEL-1,
ICONS[""] +
"no file header update required for %s" % file)
Avoid deeply nested control flow statements. Open
Open
while lines and \
(lines[0].strip() == '' or
lines[0].startswith('#')):
removed.append(lines.pop(0).strip())
Avoid deeply nested control flow statements. Open
Open
if new_lines[-1].strip():
f.write(linesep) # last empty line
f.close()