Skip to content

False positive nested-min-max #8168

@XuehaiPan

Description

@XuehaiPan

Bug description

The nested-min-max suggests max(3, max(1, 2)) to be max(3, 1, 2). However, if the min / max function takes an iterable max(iterable) instead of multiple inputs max(a, b, c). The nested min/max cannot be rewritten as a single statement max(x, max(iterable)) -> max(x, iterable).

"""test.py"""

lst = [1, 2]
max(3, max(lst))

If rewrite it to max(3, lst), it will raise:

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

Configuration

No response

Command used

pylint test.py

Pylint output

************* Module test
test.py:4:0: W3301: Do not use nested call of 'max'; it's possible to do 'max(3, lst)' instead (nested-min-max)

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

Expected behavior

No warnings.

Pylint version

pylint 2.16.0
astroid 2.14.1
Python 3.8.13 (default, Oct 21 2022, 23:50:54)

OS / Environment

No response

Additional dependencies

No response

Metadata

Metadata

Assignees

Labels

Enhancement ✨Improvement to a componentNeeds PRThis issue is accepted, sufficiently specified and now needs an implementation

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions