Python

Python

By DeepSource

Use of len(seq) - 1 to get last element of an iterable PTC-W0044
Performance
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.

New column added in database with a default value PYL-W5198
Performance

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

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
Autofix

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