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.
__unicode__
method PYL-W5101Django models should implement a __unicode__
method for string representation.
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.
object
PYL-R0205The class is inheriting from object
, which is implicit under Python 3 , hence can be safely removed from bases. Not preferred:
self
as the first argument PYL-E0213The 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.
content_type
parameter for JsonResponse()
detected PYL-R5103JsonResponse()
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-R1719The if
expression used here can be simplified to increase the code readability. Example:
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.
isinstance
calls PYL-R1701You 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 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.
Cyclic imports shall be avoided. Read why are they fatal here.
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.
__unicode__
is not callable PYL-E5101Django models require a __unicode__
method which must be callable.
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.
Object is being type casted to the same type. This is unnecessary.
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-R5102It is recommended to use JsonResponse
to return JSON content. HttpResponse(content_type='application/json)
can be replaced with just JsonResponse()
.
__init__
PYL-W0201Defining 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.
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.
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.