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

Improve code quality with static analysis #119

Merged
merged 6 commits into from
May 3, 2022

Commits on May 3, 2022

  1. Remove unnecessary lambda expression

    A lambda that calls a function without modifying any of its parameters is unnecessary. Python functions are first-class objects and can be passed around in the same way as the resulting lambda. It is recommended to remove the lambda and use the function directly.
    
    Example:
    hashify = lambda x: hash(x)
    
    It is preferred to use the function hash directly as the lambda function is calling the same function without any modifications. Another reason to avoid lambda function here is that it makes the debugging difficult. Lambdas show as <lambda> in tracebacks, where functions will display the function’s name.
    deepsource-autofix[bot] authored and EwoutH committed May 3, 2022
    Configuration menu
    Copy the full SHA
    ad9d28b View commit details
    Browse the repository at this point in the history
  2. Remove unnecessary use of comprehension

    It is unnecessary to use a comprehension just to loop over the iterable and create a list/set/dict out of it. Python has a specialized set of tools for this task: the list/set/dict constructors, which are faster and more readable.
    deepsource-autofix[bot] authored and EwoutH committed May 3, 2022
    Configuration menu
    Copy the full SHA
    1666aa1 View commit details
    Browse the repository at this point in the history
  3. Remove methods with unnecessary super delegation.

    Any method in a child class which is only calling the overridden method of any of its base class using super and doing nothing else is unnecessary. If the method isn't present in the child class, Python implicitly looks for the method in its base classes.
    
    This issue is valid only if the method in the child class and the method in the base class has the same signature.
    deepsource-autofix[bot] authored and EwoutH committed May 3, 2022
    Configuration menu
    Copy the full SHA
    3ed52a6 View commit details
    Browse the repository at this point in the history
  4. Replace multiple == checks with 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.
    deepsource-autofix[bot] authored and EwoutH committed May 3, 2022
    Configuration menu
    Copy the full SHA
    1a590e9 View commit details
    Browse the repository at this point in the history
  5. Iterate dictionary directly

    Iterate the dictionary directly instead of calling .keys(). Using for key in dictionary would always iterate the dictionary keys.
    deepsource-autofix[bot] authored and EwoutH committed May 3, 2022
    Configuration menu
    Copy the full SHA
    25529b8 View commit details
    Browse the repository at this point in the history
  6. Move dictionary inserts to its definition

    Instead of adding items to a dictionary just after creation, it should be refactored to add those items into the dict definition itself.
    deepsource-autofix[bot] authored and EwoutH committed May 3, 2022
    Configuration menu
    Copy the full SHA
    b4ce855 View commit details
    Browse the repository at this point in the history