3Top/lru2layer

View on GitHub

Showing 32 of 32 total issues

Function lru2cache has a Cognitive Complexity of 48 (exceeds 5 allowed). Consider refactoring.
Open

def lru2cache(l1_maxsize=128, none_cache=False, typed=False, l2cache_name='l2cache', inst_attr='id'):
    """Least-recently-used cache decorator.

    If *l1_maxsize* is set to None, the LRU features are disabled and the cache
    can grow without bound.
Severity: Minor
Found in lru2cache/utils.py - About 7 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 _make_key. (10)
Open

def _make_key(user_function, args, kwds, typed,
             kwd_mark = (object(),),
             fasttypes = {int, str, frozenset, type(None)},
             sorted=sorted, tuple=tuple, type=type, len=len, inst_attr='id'):
    'Make a cache key from optionally typed positional and keyword arguments'
Severity: Minor
Found in lru2cache/utils.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 _make_key has 11 arguments (exceeds 4 allowed). Consider refactoring.
Open

def _make_key(user_function, args, kwds, typed,
Severity: Major
Found in lru2cache/utils.py - About 1 hr to fix

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

    def _make_key(user_function, args, kwds, typed,
                 kwd_mark = (object(),),
                 fasttypes = {int, str, frozenset, type(None)},
                 sorted=sorted, tuple=tuple, type=type, len=len, inst_attr='id'):
        'Make a cache key from optionally typed positional and keyword arguments'
    Severity: Minor
    Found in lru2cache/utils.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

    Function l2wrapper has 5 arguments (exceeds 4 allowed). Consider refactoring.
    Open

            def l2wrapper(key, user_function, none_cache, *args, **kwds):
    Severity: Minor
    Found in lru2cache/utils.py - About 35 mins to fix

      Function lru2cache has 5 arguments (exceeds 4 allowed). Consider refactoring.
      Open

      def lru2cache(l1_maxsize=128, none_cache=False, typed=False, l2cache_name='l2cache', inst_attr='id'):
      Severity: Minor
      Found in lru2cache/utils.py - About 35 mins to fix

        Do not assign a lambda expression, use a def
        Open

            hash = lambda x: sha256(x).hexdigest()
        Severity: Minor
        Found in lru2cache/utils.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

        Unexpected spaces around keyword / parameter equals
        Open

                     kwd_mark = (object(),),
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Continuation line under-indented for hanging indent
        Open

                    ), user_function.__name__]
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        Continuation lines indentation.

        Continuation lines should align wrapped elements either vertically
        using Python's implicit line joining inside parentheses, brackets
        and braces, or using a hanging indent.
        
        When using a hanging indent these considerations should be applied:
        - there should be no arguments on the first line, and
        - further indentation should be used to clearly distinguish itself
          as a continuation line.
        
        Okay: a = (\n)
        E123: a = (\n    )
        
        Okay: a = (\n    42)
        E121: a = (\n   42)
        E122: a = (\n42)
        E123: a = (\n    42\n    )
        E124: a = (24,\n     42\n)
        E125: if (\n    b):\n    pass
        E126: a = (\n        42)
        E127: a = (24,\n      42)
        E128: a = (24,\n    42)
        E129: if (a or\n    b):\n    pass
        E131: a = (\n    42\n 24)

        Continuation line under-indented for visual indent
        Open

                     fasttypes = {int, str, frozenset, type(None)},
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        Continuation lines indentation.

        Continuation lines should align wrapped elements either vertically
        using Python's implicit line joining inside parentheses, brackets
        and braces, or using a hanging indent.
        
        When using a hanging indent these considerations should be applied:
        - there should be no arguments on the first line, and
        - further indentation should be used to clearly distinguish itself
          as a continuation line.
        
        Okay: a = (\n)
        E123: a = (\n    )
        
        Okay: a = (\n    42)
        E121: a = (\n   42)
        E122: a = (\n42)
        E123: a = (\n    42\n    )
        E124: a = (24,\n     42\n)
        E125: if (\n    b):\n    pass
        E126: a = (\n        42)
        E127: a = (24,\n      42)
        E128: a = (24,\n    42)
        E129: if (a or\n    b):\n    pass
        E131: a = (\n    42\n 24)

        Unexpected spaces around keyword / parameter equals
        Open

                     fasttypes = {int, str, frozenset, type(None)},
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Trailing whitespace
        Open

                    return result   
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        Trailing whitespace is superfluous.

        The warning returned varies on whether the line itself is blank,
        for easier filtering for those who want to indent their blank lines.
        
        Okay: spam(1)\n#
        W291: spam(1) \n#
        W293: class Foo(object):\n    \n    bang = 12

        Do not use bare 'except'
        Open

        except:
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        When catching exceptions, mention specific exceptions when possible.

        Okay: except Exception:
        Okay: except BaseException:
        E722: except:

        Continuation line under-indented for visual indent
        Open

            # url(r'^$', 'lru2cache.views.home', name='home'),
        Severity: Minor
        Found in lru2cache/urls.py by pep8

        Continuation lines indentation.

        Continuation lines should align wrapped elements either vertically
        using Python's implicit line joining inside parentheses, brackets
        and braces, or using a hanging indent.
        
        When using a hanging indent these considerations should be applied:
        - there should be no arguments on the first line, and
        - further indentation should be used to clearly distinguish itself
          as a continuation line.
        
        Okay: a = (\n)
        E123: a = (\n    )
        
        Okay: a = (\n    42)
        E121: a = (\n   42)
        E122: a = (\n42)
        E123: a = (\n    42\n    )
        E124: a = (24,\n     42\n)
        E125: if (\n    b):\n    pass
        E126: a = (\n        42)
        E127: a = (24,\n      42)
        E128: a = (24,\n    42)
        E129: if (a or\n    b):\n    pass
        E131: a = (\n    42\n 24)

        Continuation line under-indented for visual indent
        Open

            # url(r'^blog/', include('blog.urls')),
        Severity: Minor
        Found in lru2cache/urls.py by pep8

        Continuation lines indentation.

        Continuation lines should align wrapped elements either vertically
        using Python's implicit line joining inside parentheses, brackets
        and braces, or using a hanging indent.
        
        When using a hanging indent these considerations should be applied:
        - there should be no arguments on the first line, and
        - further indentation should be used to clearly distinguish itself
          as a continuation line.
        
        Okay: a = (\n)
        E123: a = (\n    )
        
        Okay: a = (\n    42)
        E121: a = (\n   42)
        E122: a = (\n42)
        E123: a = (\n    42\n    )
        E124: a = (24,\n     42\n)
        E125: if (\n    b):\n    pass
        E126: a = (\n        42)
        E127: a = (24,\n      42)
        E128: a = (24,\n    42)
        E129: if (a or\n    b):\n    pass
        E131: a = (\n    42\n 24)

        Unexpected spaces around keyword / parameter equals
        Open

                     kwd_mark = (object(),),
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        Don't use spaces around the '=' sign in function arguments.

        Don't use spaces around the '=' sign when used to indicate a
        keyword argument or a default parameter value, except when
        using a type annotation.
        
        Okay: def complex(real, imag=0.0):
        Okay: return magic(r=real, i=imag)
        Okay: boolean(a == b)
        Okay: boolean(a != b)
        Okay: boolean(a <= b)
        Okay: boolean(a >= b)
        Okay: def foo(arg: int = 42):
        Okay: async def foo(arg: int = 42):
        
        E251: def complex(real, imag = 0.0):
        E251: return magic(r = real, i = imag)
        E252: def complex(real, image: float=0.0):

        Blank line contains whitespace
        Open

                    
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        Trailing whitespace is superfluous.

        The warning returned varies on whether the line itself is blank,
        for easier filtering for those who want to indent their blank lines.
        
        Okay: spam(1)\n#
        W291: spam(1) \n#
        W293: class Foo(object):\n    \n    bang = 12

        Blank line contains whitespace
        Open

                        
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        Trailing whitespace is superfluous.

        The warning returned varies on whether the line itself is blank,
        for easier filtering for those who want to indent their blank lines.
        
        Okay: spam(1)\n#
        W291: spam(1) \n#
        W293: class Foo(object):\n    \n    bang = 12

        Do not use bare 'except'
        Open

                    except:
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        When catching exceptions, mention specific exceptions when possible.

        Okay: except Exception:
        Okay: except BaseException:
        E722: except:

        No newline at end of file
        Open

            return decorating_function
        Severity: Minor
        Found in lru2cache/utils.py by pep8

        Trailing blank lines are superfluous.

        Okay: spam(1)
        W391: spam(1)\n
        
        However the last line should end with a new line (warning W292).
        Severity
        Category
        Status
        Source
        Language