Skip to content

Fix DeepSource alerts

  • print statement has no effect
  • Useless return detected
  • 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.
  • Consider using literal syntax to create the data structure
    • 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().
  • This is a Python 3 script
    • Remove Python2 test, this will at the same time remove a DeepSource false positive about reload being an undefined name.
  • Dangerous default argument
    • Do not use a mutable like list or dictionary as a default value to an argument. Python’s default arguments are evaluated once when the function is defined. Using a mutable default argument and mutating it will mutate that object for all future calls to the function as well.
  • Function/method with an empty body
  • Logging is not lazy
    • The logging statement has the call of the formlogging.(format_string % (format_args...)). For such calls, it is recommended to leave string interpolation to the logging method itself and be written aslogging.(format_string, format_args...) so that the program may avoid incurring the cost of the interpolation in those cases in which no message will be logged. For more details, see PEP 282.

Partially fixes #341 (closed).

Edited by Dimitri Papadopoulos Orfanos

Merge request reports