nested-min-max (PLW3301)
Derived from the Pylint linter.
Fix is sometimes available.
What it does
Checks for nested min
and max
calls.
Why is this bad?
Nested min
and max
calls can be flattened into a single call to improve
readability.
Example
Use instead:
Fix safety
This fix is always unsafe and may change the program's behavior for types without full
equivalence relations, such as float comparisons involving NaN
.
print(min(2.0, min(float("nan"), 1.0))) # before fix: 2.0
print(min(2.0, float("nan"), 1.0)) # after fix: 1.0
print(max(1.0, max(float("nan"), 2.0))) # before fix: 1.0
print(max(1.0, float("nan"), 2.0)) # after fix: 2.0