redefined-outer-name / W0621#

Message emitted:

Redefining name %r from outer scope (line %s)


Used when a variable's name hides a name defined in an outer scope or except handler.

Problematic code:

count = 10

def count_it(count):  # [redefined-outer-name]
    for i in range(count):

Correct code:

count = 10

def count_it(limit):
    for i in range(limit):

Additional details:

A common issue is that this message is triggered when using pytest fixtures:

import pytest

def setup():

def test_something(setup):  # [redefined-outer-name]

One solution to this problem is to explicitly name the fixture:

def setup_fixture():

Alternatively pylint plugins like pylint-pytest can be used.

Created by the variables checker.