[英]better alternative to flake8's "E902 TokenError: EOF in multi-line statement"
I do understand the E902 error, however I do think it's a bit "messy".我确实理解 E902 错误,但我确实认为它有点“混乱”。 This is for 2 reasons:这有两个原因:
python
on the file) to find the exact line.更重要的是,我觉得这个错误总是指向第 1 行字符 1 是非常无益的。这意味着由我开始查看代码(有时是 1000 行长的文件)到我忘记关闭的确切位置括号,或运行其他工具(例如仅在文件上运行python
)以找到确切的行。 Also, this means that my editor (VIM) will not show any error for the line I'm working on;此外,这意味着我的编辑器 (VIM) 不会显示我正在处理的行的任何错误; I will only see the error if I scroll up all the way.如果我一直向上滚动,我只会看到错误。I guess my questions are threefold:我想我的问题有三个:
python
since there does not seem to be a way to tell python to only parse the file but not actually run it.).也许是 flake8 的包装器,在出现 E902 错误的情况下,它会使用其他一些方法来找到更准确的位置(请注意,作为 flake8 的一部分的 pyflakes 确实找到了正确的行;运行python
可能不是一个好主意,因为在那里)似乎不是告诉 python 只解析文件而不实际运行它的方法。)。 I'm sure I can create such a wrapper myself, but if other/smarter people already made one, I'd prefer to reuse their work.我确信我自己可以创建这样的包装器,但是如果其他/更聪明的人已经制作了一个,我更愿意重用他们的工作。For completeness, the following code shows the issue:为了完整起见,以下代码显示了问题:
def x():
pass
x(
a = 1
b = 2
Both pyflakes and python show an error in line 7 (which at least is very close to where the error is made), whereas flake8 will just show the error on 1:1 pyflakes 和 python 都在第 7 行显示错误(至少非常接近出错的地方),而 flake8 只会在 1:1 上显示错误
answering all three of the questions (usually separate questions should be separate questions on SO but...):回答所有三个问题(通常单独的问题应该是关于 SO 的单独问题,但是......):
the E / F / W codes do not mean error / failure / warning -- the prefix is a coincidence. E/F/W 代码并不意味着错误/失败/警告——前缀是一个巧合。 F codes come from pyflakes, E and W codes come from pycodestyle (though there are two special E codes inherited from pycodestyle that remain -- E902 and E999 for OSError and SyntaxError -- I'd love to change this but the sheer number of people using flake8 makes breaking changes tricky) F 代码来自 pyflakes,E 和 W 代码来自 pycodestyle(尽管有两个从 pycodestyle 继承的特殊 E 代码仍然存在——用于 OSError 和 SyntaxError 的 E902 和 E999——我很想改变这一点,但人数众多使用 flake8 使重大更改变得棘手)
it is col 1 line 1 because this error comes from the tokenizer and it reports the error out-of-bounds on the last line of the file.它是第 1 行第 1 行,因为此错误来自标记器,并且它在文件的最后一行报告越界错误。 the tokenizer is not very good about giving precise error locations分词器不太擅长给出精确的错误位置
it is considered a bug, but nobody has volunteered to work on it yet, if I'm reading it correctly it should be a 2 line fix -- you can read more about the bug here: https://github.com/PyCQA/flake8/issues/740它被认为是一个错误,但还没有人自愿处理它,如果我正确阅读它应该是 2 行修复 - 您可以在此处阅读有关该错误的更多信息: https : //github.com/PyCQA /flake8/issues/740
disclaimer: I'm the current flake8 maintainer免责声明:我是当前的 flake8 维护者
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.