Python

Python

Made by DeepSource
Implicit enumerate calls found PTC-W0060
Anti-pattern
Major
Autofix

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.

Pythagorean calculation detected with sub-optimal numerics PTC-W0028
Anti-pattern
Major
Autofix

Calculating the length of the hypotenuse using the standard formula c = sqrt(a**2 + b**2) may lead to overflow if the two other sides are both very large. Even though c will not be much bigger than max(a, b), either a**2 or b**2 (or both) could be. Thus, the calculation could overflow, even though the result is well within representable range. It is recommended to use the built-in function hypot(a,b) from the math library.

Simplify boolean expression PYL-R1709
Anti-pattern
Major

The boolean expression with redundant pre-python 2.5 ternary syntax is used and can be simplified for better readability. Please look at the issue text for suggestion.

Unnecessary delete statement in a local scope PTC-W0043
Anti-pattern
Major
Autofix

Passing a local variable to a del statement results in that variable being removed from the local namespace. When exiting a function all local variables are deleted, so it is unnecessary to explicitly delete variables in such cases.

Model missing __unicode__ method PYL-W5101
Anti-pattern
Minor

Django models should implement a __unicode__ method for string representation.

Function with cyclomatic complexity higher than threshold PY-R1000
Anti-pattern
Minor

A function with high cyclomatic complexity can be hard to understand and maintain. Cyclomatic complexity is a software metric that measures the number of independent paths through a function. A higher cyclomatic complexity indicates that the function has more decision points and is more complex.

Consider using max builtin PTC-W0042
Anti-pattern
Major
Autofix

It is unnecessary to use an if statement to check the maximum of two values and then assign the value to a name. You can use the max built-in do do this. It is straightforward and more readable.

Named lambda expression detected FLK-E731
Anti-pattern
Minor

Lambdas should not be assigned to a variable. Instead, they should be defined as functions. The primary reason for this is debugging. Lambdas show as <lambda> in tracebacks, where functions will display the function’s name.

HttpResponse used to return JSON response PYL-R5101
Anti-pattern
Major

It is recommended to use JsonResponse to return JSON data instead of HttpResponse. HttpResponse(json.dumps(data)) can be replaced with JsonResponse(data), where data is a JSON-serializable object.

Abstract method does not raise NotImplementedError PTC-W0053
Anti-pattern
Major
Autofix

Abstract methods should raise NotImplementeError when they require derived classes to override the method, or while the class is being developed to indicate that the real implementation still needs to be added.

Model has __unicode__ method PYL-W5102
Anti-pattern
Major

Django models should not implement a __unicode__ method for string representation when using Python 3. Use __str__ instead.

Consider using TextField instead of CharField PTC-W0904
Anti-pattern
Major
Autofix

CharField highlighted in the issue has a max_length > 256. It is recommended to use TextField for such long fields. CharField should only be used for smaller strings.

Unused format string argument PYL-W1304
Anti-pattern
Major

The format string that uses named field(s), is used with an argument that is not required by the format string. It is recommended to remove unused keyword-arguments for a better readability.

Useless inheritance from object PYL-R0205
Anti-pattern
Major
Autofix

The class is inheriting from object, which is implicit under Python 3 , hence can be safely removed from bases. Not preferred:

if expression used can be simplified PYL-R1719
Anti-pattern
Minor
Autofix

The if expression used here can be simplified to increase the code readability. Example:

Redundant content_type parameter for JsonResponse() detected PYL-R5103
Anti-pattern
Major

JsonResponse() contains content_type parameter. This is either redundant or the content_type is not JSON, which is probably an error.

Empty module found PTC-W0030
Anti-pattern
Major
Autofix

Do not pollute your project with empty files. It is recommended to either delete this file or drop some documentation in it explaining why it is there.

Unnecessary literal PTC-W0018
Anti-pattern
Minor
Autofix

It is unnecessary to use a list or tuple literal within a call to tuple, list, set, or dict since there is a literal syntax for these types.

Prefer list.extend(x) over list.append(*x) PY-W0080
Anti-pattern
Major

The append list method only takes one argument. So, if you have a list items, a call like list.append(*items) only works if items has a single element in it. If there is more than one element in items, this code will crash.

Unnecessary None provided as default PTC-W0039
Anti-pattern
Minor
Autofix

It is unnecessary to provide None as the default value when the key is not present in the dictionary as get implicitly returns None. Not preferred: