nonlocal-without-binding (PLE0117) 源自 Pylint 代码检查工具。 作用 检查没有绑定的 nonlocal 名称。 为什么这不好? nonlocal 名称必须绑定到外部作用域中的名称。违反此规则会在运行时导致 SyntaxError。 示例 def foo(): def get_bar(self): nonlocal bar ... 建议改为 def foo(): bar = 1 def get_bar(self): nonlocal bar ... 参考 Python 文档:nonlocal 语句 PEP 3104 – 访问外部作用域中的名称