datahuborg/datahub

View on GitHub
src/apps/dbwipes/util.py

Summary

Maintainability
A
3 hrs
Test Coverage

Function where_to_sql has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
Open

def where_to_sql(where_json, negate=False):
    is_type = lambda s, types: any([t in s for t in types])
    l = []
    args = []
    for clause_json in where_json:
Severity: Minor
Found in src/apps/dbwipes/util.py - About 2 hrs to fix

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 where_to_sql. (11)
Open

def where_to_sql(where_json, negate=False):
    is_type = lambda s, types: any([t in s for t in types])
    l = []
    args = []
    for clause_json in where_json:
Severity: Minor
Found in src/apps/dbwipes/util.py by radon

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.

Source: http://radon.readthedocs.org/en/latest/intro.html

Function default has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
Open

    def default(self, o):
        if isinstance(o, float):
            if o == float('inf'):
                return 1e100
            elif o == float('-inf'):
Severity: Minor
Found in src/apps/dbwipes/util.py - About 45 mins to fix

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 too many return statements within this function.
Open

        return super(SummaryEncoder, self).default(o)
Severity: Major
Found in src/apps/dbwipes/util.py - About 30 mins to fix

    Invalid escape sequence '\s'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Invalid escape sequence '\s'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Ambiguous variable name 'l'
    Open

        l = []
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Never use the characters 'l', 'O', or 'I' as variable names.

    In some fonts, these characters are indistinguishable from the
    numerals one and zero. When tempted to use 'l', use 'L' instead.
    
    Okay: L = 0
    Okay: o = 123
    Okay: i = 42
    E741: l = 0
    E741: O = 123
    E741: I = 42
    
    Variables can be bound in several other contexts, including class
    and function definitions, 'global' and 'nonlocal' statements,
    exception handlers, and 'with' and 'for' statements.
    In addition, we have a special handling for function parameters.
    
    Okay: except AttributeError as o:
    Okay: with lock as L:
    Okay: foo(l=12)
    Okay: for a in foo(l=12):
    E741: except AttributeError as O:
    E741: with lock as l:
    E741: global I
    E741: nonlocal l
    E741: def foo(l):
    E741: def foo(l=12):
    E741: l = foo(l=12)
    E741: for l in range(10):
    E742: class I(object):
    E743: def l(x):

    Invalid escape sequence '\s'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Invalid escape sequence '\s'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Do not assign a lambda expression, use a def
    Open

        is_type = lambda s, types: any([t in s for t in types])
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Compound statements (on the same line) are generally discouraged.

    While sometimes it's okay to put an if/for/while with a small body
    on the same line, never do this for multi-clause statements.
    Also avoid folding such long lines!
    
    Always use a def statement instead of an assignment statement that
    binds a lambda expression directly to a name.
    
    Okay: if foo == 'blah':\n    do_blah_thing()
    Okay: do_one()
    Okay: do_two()
    Okay: do_three()
    
    E701: if foo == 'blah': do_blah_thing()
    E701: for x in lst: total += x
    E701: while t < 10: t = delay()
    E701: if foo == 'blah': do_blah_thing()
    E701: else: do_non_blah_thing()
    E701: try: something()
    E701: finally: cleanup()
    E701: if foo == 'blah': one(); two(); three()
    E702: do_one(); do_two(); do_three()
    E703: do_four();  # useless semicolon
    E704: def f(x): return 2*x
    E731: f = lambda x: 2*x

    Invalid escape sequence ')'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Invalid escape sequence '\w'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Invalid escape sequence '('
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Invalid escape sequence '\w'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Invalid escape sequence '\,'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Invalid escape sequence '\s'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    Invalid escape sequence '\w'
    Open

            '(?P<func>\w+)\(\s*(?P<col>[\w\,\s]+)\s*\)\s*(as\s+(?P<alias>\w+))?')
    Severity: Minor
    Found in src/apps/dbwipes/util.py by pep8

    Invalid escape sequences are deprecated in Python 3.6.

    Okay: regex = r'\.png$'
    W605: regex = '\.png$'

    There are no issues that match your filters.

    Category
    Status