Python

Python

Made by DeepSource
New column added in database with a default value PYL-W5198
Performance
Major

The preferred way is to add a new DB column with null=True because it will be created instantly and then possibly populate the table with the desired default values. Adding a default value will lead to a performance issue if the existing table has a large number of rows.

Expression not assigned PYL-W0106
Performance
Major

An expression that is not a function call is assigned to nothing. Probably something else was intended here. We recommend to review this.

Consider using literal syntax to create the data structure PTC-W0019
Performance
Minor
Autofix

Using the literal syntax can give minor performance bumps compared to using function calls to create dict, list and tuple.

Built-in function len used as condition PYL-C1802
Performance
Major
Autofix

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.

Unnecessary comprehension PTC-W0016
Performance
Major
Autofix

The built-in function being used does not require comprehension and can work directly with a generator expression.

Consider using join PYL-R1713
Performance
Major
Autofix

Consider using str.join(sequence) instead of joining the elements of a sequence using for loop iteration. str.join(sequence) is faster, uses less memory and increases readability compared to a for loop iteration.

Consider using in PYL-R1714
Performance
Major
Autofix

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.

Consider using a dictionary comprehension PYL-R1717
Performance
Major
Autofix

Although there is nothing syntactically wrong with this code, it is hard to read and can be simplified to a dict comprehension. Using dictionary comprehension is more performant since there is no need to create a transient list.

Consider using a set comprehension PYL-R1718
Performance
Major
Autofix

Although there is nothing syntactically wrong with this code, it is hard to read and can be simplified to a set comprehension. Using set comprehension is more performant since there is no need to create a transient list.

Unnecessary use of comprehension PYL-R1721
Performance
Major
Autofix

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.

Use of len(seq) - 1 to get last element of an iterable PTC-W0044
Performance
Major
Autofix

There’s no need to calculate length of an iterable in order to fetch the last element of the iterable. You can provide a negative index -1 to it directly in orger to get the last element. In this way, you don't have to iterate over the sequence using len to get the last index when your purpose is only to get the last element.

Redundant list comprehension can be replaced using generator PYL-R1728
Performance
Minor

Using a container in place of a generator for a calls that can accept both, slows down the performance. Consider using generators for all function calls which accept both containers and genertors.

Consider using f-strings PYL-C0209
Performance
Minor

f-strings are the fastest way to format strings as compared to the following methods: * using format specifiers %

Lazy formatting of message string passed to logging module PYL-W1202
Performance
Minor

Formatting the message manually before passing it to a logging call does unnecessary work if logging in disabled. Consider using the logging module's built-in formatting features to avoid that.

Formatted string passed to logging module PYL-W1203
Performance
Minor

Formatting the message manually before passing it to a logging call does unnecessary work if logging is disabled. Consider using the logging module's built-in formatting features to avoid that.