使用 PyFlakes 和 del 运算符

发布于 2024-09-17 04:55:25 字数 365 浏览 2 评论 0原文

在 Python 函数中使用 del 时,我从 PyFlakes 收到误报,告诉我该变量未定义。

def foo(bar):
    # what if it's ham? eww
    if bar == 'ham':
        del bar
        return
    # otherwise yummy!
    print bar

上面的函数将返回以下错误:

C:\temp\test.py:7: undefined name 'bar'

即使该函数可以工作。 有谁知道有一个补丁可以调整 ast 树解析以改变它的处理方式?如果其他人也遇到过这种情况?

When making use of del in a Python function, I'm getting false positives from PyFlakes telling me that the variable is undefined.

def foo(bar):
    # what if it's ham? eww
    if bar == 'ham':
        del bar
        return
    # otherwise yummy!
    print bar

The above function will return the following error:

C:\temp\test.py:7: undefined name 'bar'

Even though the function will work.
Does anyone know of a patch to tweak the ast tree parsing to change how it's being handled? If this something others have run into?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鹿港小镇 2024-09-24 04:55:25

那么你的问题是什么?删除参数名称根本没有任何意义,所以这无论如何都不是真正的问题......

So what is your question? Deleting parameter names does not make any sense at all, so this is no real issue anyways ...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文