Skip to content

redefined-argument-from-local (PLR1704)#

Derived from the Pylint linter.

This rule is unstable and in preview. The --preview flag is required for use.

What it does#

Checks for variables defined in for, try, with statements that redefine function parameters.

Why is this bad?#

Redefined variable can cause unexpected behavior because of overridden function parameter. If nested functions are declared, inner function's body can override outer function's parameter.


def show(host_id=10.11):
    for host_id, host in [[12.13, "Venus"], [14.15, "Mars"]]:
        print(host_id, host)

Use instead:

def show(host_id=10.11):
    for inner_host_id, host in [[12.13, "Venus"], [14.15, "Mars"]]:
        print(host_id, inner_host_id, host)