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.
Too many decision blocks were found, which is why the code has been tagged as complex. You should consider refactoring the code for simplicity. Read more about cyclomatic complexity here.
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
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
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.
deletestatement in a local scope PTC-W0043
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.
Django models should implement a
__unicode__ method for string representation.
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.
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.
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.
HttpResponseused to return JSON response PYL-R5101
It is recommended to use
JsonResponse to return JSON data instead of HttpResponse.
HttpResponse(json.dumps(data)) can be replaced with
data is a JSON-serializable object.
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.
Django models should not implement a
__unicode__ method for string representation when using Python 3. Use
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.
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.
The class is inheriting from
object, which is implicit under Python 3 , hence can be safely removed from bases. Not preferred:
ifexpression used can be simplified PYL-R1719
if expression used here can be simplified to increase the code readability. Example:
content_type parameter. This is either redundant or the content_type is not JSON, which is probably an error.
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.
It is unnecessary to use a
tuple literal within a call to
dict since there is a literal syntax for these types.
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.