Python

Python

By DeepSource

Pythagorean calculation detected with sub-optimal numericsPTC-W0028
Anti-pattern
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 expressionPYL-R1709
Anti-pattern

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.

File opened without the `with` statementPTC-W0010
Anti-pattern

Opening a file using with statement is preferred as function open implements the context manager protocol that releases the resource when it is outside of the with block. Not doing so requires you to manually release the resource.

Use `items()` to iterate over a dictionaryPTC-W0011
Anti-pattern

The preferred way to iterate over the key-value pairs of a dictionary is to declare two variables in a for loop, and then call dictionary.items() (or dictionary.iteritems() for Python2), where dictionary is the name of your variable representing a dictionary.'