警告:重新定义DouterName意外静音

2024-03-29 00:28:05 发布

您现在位置:Python中文网/ 问答频道 /正文

默认情况下,pylint v2.9.6会给出以下警告:

spam.py

"""Docstring."""


def spam():
    """Docstring."""
    spam = 42
    return spam

pylint警告

spam.py|6 col 5 warning| [redefined-outer-name] Redefining name 'spam' from outer scope (line 4) [python/pylint]

创建以下.pylintrc后,不再给出警告。这是不可取的

.pylintrcpossible locations

[VARIABLES]

# A regular expression matching the name of dummy variables (i.e. expected to
# not be used).
#dummy-variables-rgx=_+$|(_[a-zA-Z0-9_]*[a-zA-Z0-9]+?$)|dummy|^ignored_|^unused_
dummy-variables-rgx=

为什么?