You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
min(iterable) produces the minimum element of the iterable. min(value, value, ...) produces the minimum of all its arguments; it does not notice iterables among the values. Therefore min(value, min(iterable)) is a useful thing to do, but min(value, iterable) will typically throw a TypeError because int and list[int] (for instance) are not comparable. The same applies to max().
To sum up: The code below is the natural way to take the minimum/maximum of an iterable plus some other values, and it should not trigger any W3301 warnings.
************* Module a
a.py:18:8: W3301: Do not use nested call of 'min'; it's possible to do 'min(lo, hi, elements)' instead (nested-min-max)
a.py:19:8: W3301: Do not use nested call of 'max'; it's possible to do 'max(lo, hi, elements)' instead (nested-min-max)
Expected behavior
Do not issue W3301 when the inner call(s) to min/max pass only one argument.
zenlyj
added
False Positive 🦟
A message is emitted but nothing is wrong with the code
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
and removed
Needs triage 📥
Just created, needs acknowledgment, triage, and proper labelling
False Positive 🦟
A message is emitted but nothing is wrong with the code
Needs PR
This issue is accepted, sufficiently specified and now needs an implementation
labels
Nov 8, 2024
Thank you for this, an alternative to min(value, min(iterable)) is min(value, *iterable), without the nested call.
I agree that the suggested message - Do not use nested call of 'min'; it's possible to do 'min(lo, hi, elements)' instead is inaccurate when the arguments are not comparable. But at the same time, i am not sure if we should not raise any message when the inner call has only one argument, as it could lead to false negatives like:
We'll probably want to keep the check as it is when the passed arguments are untyped, and perhaps improve the accuracy of the suggested code correction when typing is involved.
Bug description
min(iterable)
produces the minimum element of the iterable.min(value, value, ...)
produces the minimum of all its arguments; it does not notice iterables among the values. Thereforemin(value, min(iterable))
is a useful thing to do, butmin(value, iterable)
will typically throw a TypeError becauseint
andlist[int]
(for instance) are not comparable. The same applies tomax()
.To sum up: The code below is the natural way to take the minimum/maximum of an iterable plus some other values, and it should not trigger any W3301 warnings.
Command used
Pylint output
Expected behavior
Do not issue W3301 when the inner call(s) to min/max pass only one argument.
Pylint version
The text was updated successfully, but these errors were encountered: