Python

Python

Made by DeepSource
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.

Model missing __unicode__ method PYL-W5101
Anti-pattern
Minor

Django models should implement a __unicode__ method for string representation.

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.

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:

Method should have self as the first argument PYL-E0213
Anti-pattern
Major

The first argument of instance methods must be named self. This is considered an error since this convention is so common that you shouldn't break it.

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.

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:

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.

Consider merging isinstance calls PYL-R1701
Anti-pattern
Major
Autofix

You can pass a tuple of types you want to check as the second argument to isinstance. If the object matches with any of the types, it will return True else False.

Comparing to literal PYL-R0123
Anti-pattern
Major

Comparing an object to a literal is usually something you do not want to do, since you can compare to a different literal than what was expected altogether.

Bad string strip call PYL-E1310
Anti-pattern
Major

The argument to a str.{l,r,}strip call contains a duplicate character. Although this will not cause an error, but it is recommended to remove duplicates. This may affect readability.

Model's __unicode__ is not callable PYL-E5101
Anti-pattern
Major

Django models require a __unicode__ method which must be callable.

Exception arguments suggest string formatting might be intended PYL-W0715
Anti-pattern
Major

Found multiple arguments to an exception constructor, the first of them a string literal containing what appears to be placeholders intended for formatting. In this case, it is recommended to format the message properly.

Unnecessary typecast PTC-W0020
Anti-pattern
Minor
Autofix

Object is being type casted to the same type. This is unnecessary.

Chained comparison detected PYL-R1716
Anti-pattern
Minor

Detected boolean operation likea < b and b < c. It is recommended to refactor it to a < b < c. It improves readability,

HttpResponse() returns application/json content type PYL-R5102
Anti-pattern
Major

It is recommended to use JsonResponse to return JSON content. HttpResponse(content_type='application/json) can be replaced with just JsonResponse().

Attribute defined outside __init__ PYL-W0201
Anti-pattern
Minor

Defining an instance attribute outside __init__ affects the readability of code. It is expected to find all the attributes an instance may have by reading its __init__ method. If there is a need to initialize attribute via sub-initialization methods, it is recommended to assign attributes to None in the init then call the sub-initialization methods.

Re-definition found for builtin function PYL-W0622
Anti-pattern
Major

Defining a local variable or function with the same name as a built-in object makes the built-in object unusable within the current scope and makes the code prone to bugs.

Keyword argument defined before variable positional arguments PYL-W1113
Anti-pattern
Major

On defining a keyword argument before variable positional arguments, one can end up in having multiple values passed for the aforementioned parameter in case the method is called with keyword arguments. It is recommended to define keyword arguments after variable positional arguments.