Skip to content
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

nested-min-max (W3301) is still giving a wrong suggestion in some cases #8524

Closed
vejkse opened this issue Apr 1, 2023 · 0 comments · Fixed by #9131
Closed

nested-min-max (W3301) is still giving a wrong suggestion in some cases #8524

vejkse opened this issue Apr 1, 2023 · 0 comments · Fixed by #9131
Labels
Bug 🪲 Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Milestone

Comments

@vejkse
Copy link

vejkse commented Apr 1, 2023

Bug description

With the following code

""" An example where pylint gives a wrong suggestion """
max(3, max([5] + [i for i in range(6,10) if i % 2 == 0]))

pylint detects a nested call of max and suggests to just remove the inner max. But this leads to a type error:

TypeError: '>' not supported between instances of 'list' and 'int'

Configuration

No response

Command used

pylint a.py

Pylint output

************* Module a
a.py:2:0: W3301: Do not use nested call of 'max'; it's possible to do 'max(3, [5] + [i for i in range(6, 10) if i % 2 == 0])' instead (nested-min-max)

------------------------------------------------------------------
Your code has been rated at 0.00/10 (previous run: 0.00/10, +0.00)

Expected behavior

At the very least not give a wrong suggestion, but ideally give a right one, like for other instances of this problem recently addressed in #8168 and #8234.

For instance, with

max(3, max([5] + [4]))

we now get the working suggestion to replace it with

max(3, *[5] + [4])

so we could suggest in this case too to add a *:

max(3, *[5] + [i for i in range(6, 10) if i % 2 == 0])

(In this case, one could of course even be smarter, but this may be too specific.)

Pylint version

pylint 2.17.0
astroid 2.15.0
Python 3.10.10 (main, Mar  5 2023, 22:26:53) [GCC 12.2.1 20230201]

OS / Environment

No response

Additional dependencies

No response

@vejkse vejkse added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Apr 1, 2023
@Pierre-Sassoulas Pierre-Sassoulas added Bug 🪲 Needs PR This issue is accepted, sufficiently specified and now needs an implementation and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Apr 1, 2023
@Pierre-Sassoulas Pierre-Sassoulas added this to the 3.0.2 milestone Oct 11, 2023
github-actions bot pushed a commit that referenced this issue Oct 11, 2023
Pierre-Sassoulas pushed a commit that referenced this issue Oct 11, 2023
Closes #8524

(cherry picked from commit ce8d1a9)

Co-authored-by: theirix <theirix@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug 🪲 Needs PR This issue is accepted, sufficiently specified and now needs an implementation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants