Skip to content

False positive: nested-min-max drops trailing arguments when suggesting a splat rewrite #11134

Description

@Synvoya

Bug description

nested-min-max (W3301), when it suggests flattening a nested min/max into a splat call, silently drops every argument positioned after the splatted one, so the suggested code computes a different result than the original.

LIST = [1, 2, 3]
max(max(LIST), 5, 7)   # suggests `max(*LIST)`     -> drops 5, 7  (evaluates to 3, not 7)
max(4, max(LIST), 7)   # suggests `max(4, *LIST)`  -> drops 7

Command used

pylint --disable=all --enable=nested-min-max a.py

Pylint output

a.py:2:0: W3301: Do not use nested call of 'max'; it's possible to do 'max(*LIST)' instead (nested-min-max)

Expected behavior

The suggestion should preserve the trailing arguments, e.g. max(max(LIST), 5, 7) -> max(*LIST, 5, 7).

Root cause

In pylint/checkers/nested_min_max.py, the splat rewrite builds the new args with *fixed_node.args[idx + 1 : idx]. That slice has start > stop, so it is always empty and every argument after the splat position is discarded. It should be fixed_node.args[idx + 1 :].

This is the same class of defect as #11130 / #11131 (the key=/default= drop), via a different code path — existing fixtures only splat the last argument, where the empty slice happens to coincide with the correct one, so the bug is untested.

Pylint version

pylint 4.x (main branch), astroid 4.x

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions