-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
False positive nested-min-max
#8168
Comments
I think this makes sense and follows the logic for pylint also not raising the message for these types of inputs:
|
What is wrong with |
It allocates an extra list object, which might be undesirable. How about splicing in the list? lst = [1, 2]
max(3, *lst) |
Splatting the list (or allocating a new one) might be ways to avoid the nested min/max - but that's not what the fixer recommends. It says
Which is incorrect in this case, no? |
Maybe it could suggest |
I’m not sure I should open a new issue or not, but the current solution (in pylint 2.17.0) still gives wrong suggestions in some cases. With max(3, max([5] + [4])) we get the correct suggestion
but with max(3, max([5] + [i for i in range(6,10) if i % 2 == 0])) we get the incorrect one
|
@vejkse thank you for reporting. Can you open a new issue please ? It's going to get lost in a closed issue otherwise. |
Bug description
The
nested-min-max
suggestsmax(3, max(1, 2))
to bemax(3, 1, 2)
. However, if themin
/max
function takes an iterablemax(iterable)
instead of multiple inputsmax(a, b, c)
. The nested min/max cannot be rewritten as a single statementmax(x, max(iterable)) -> max(x, iterable)
.If rewrite it to
max(3, lst)
, it will raise:Configuration
No response
Command used
Pylint output
Expected behavior
No warnings.
Pylint version
OS / Environment
No response
Additional dependencies
No response
The text was updated successfully, but these errors were encountered: