Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Deepsource issues #2085

Merged
merged 5 commits into from
Nov 2, 2022

Commits on Nov 2, 2022

  1. DeepSource issue: Built-in function len used as condition

    Using the `len` function to check if a sequence is empty is not idiomatic
    and can be less performant than checking the truthiness of the object.
    
    `len` doesn't know the context in which it is called, so if computing the
    length means traversing the entire sequence, it must; it doesn't know
    that the result is just being compared to 0. Computing the boolean value
    can stop after it sees the first element, regardless of how long the
    sequence actually is.
    DimitriPapadopoulos committed Nov 2, 2022
    Configuration menu
    Copy the full SHA
    9b4434f View commit details
    Browse the repository at this point in the history
  2. DeepSource issue: Consider using literal syntax to create the data st…

    …ructure
    
    Using the literal syntax can give minor performance bumps compared to
    using function calls to create `dict`, `list` and `tuple`.
    
    This is because here, the name dict must be looked up in the global
    scope in case it has been rebound. Same goes for the other two types
    `list()` and `tuple()`.
    DimitriPapadopoulos committed Nov 2, 2022
    Configuration menu
    Copy the full SHA
    686f547 View commit details
    Browse the repository at this point in the history
  3. DeepSource issue: Consider decorating method with @staticmethod

    The method doesn't use its bound instance. Decorate this method with
    `@staticmethod` decorator, so that Python does not have to instantiate
    a bound method for every instance of this class thereby saving memory
    and computation. Read more about staticmethods here.
    DimitriPapadopoulos committed Nov 2, 2022
    Configuration menu
    Copy the full SHA
    76944f2 View commit details
    Browse the repository at this point in the history
  4. DeepSource issue: Consider using in

    To check if a variable is equal to one of many values, combine the values
    into a tuple and check if the variable is contained `in` it instead of
    checking for equality against each of the values. This is faster, less
    verbose, and more readable.
    DimitriPapadopoulos committed Nov 2, 2022
    Configuration menu
    Copy the full SHA
    0f6d889 View commit details
    Browse the repository at this point in the history
  5. DeepSource issue: Implicit enumerate calls found

    Using `range(len(...))` is not pythonic. Python does not have not
    index-based loops. Instead, it uses collection iterators.
    
    Python has a built-in method enumerate which adds a counter to an
    iterable. Using this, you can access the counter and the value from
    the iterable at the same time. It is therefore recommended to replace
    `range(len(...))` with `enumerate(...)`.
    DimitriPapadopoulos committed Nov 2, 2022
    Configuration menu
    Copy the full SHA
    502fb86 View commit details
    Browse the repository at this point in the history