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

W3301 nested min/max consider different types #1006

Open
klokailo opened this issue Jan 29, 2024 · 0 comments
Open

W3301 nested min/max consider different types #1006

klokailo opened this issue Jan 29, 2024 · 0 comments

Comments

@klokailo
Copy link

The following lines find the maximum value between a list and a single number:

my_list = [1, 2, 3]
my_number = 5
maximum = max(5, max(my_list)) # Returns 5

Python TA incorrectly flags this for W3301 "nested min/max", stating that we would be able to shorten the last line to:

maximum = max(5, my_list)

This is incorrect, since the python builtin max can only compare values of the same type (and cannot compare list[int] and int here). The replacement suggested by PythonTA would cause a runtime error.

W3301 should not be flagged if the parameters passed into the builtin mins/maxs are of different types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant