PEP 8:E128 有时需要空格,有时不需要
这篇帖子的答案建议 PEP 8: E128 当第一行后面的行全部用括号括起来时,需要在行上有空格。但是,对于 if
语句,情况似乎并非如此。您可以看到前三行没有警告,而以下行则有警告,因为它们确实有空格:
我错过了什么吗?如果有帮助的话,我正在使用 Pycharm 社区版。
使用的代码:
def main(user_input):
if (";" not in user_input
and "DROP " not in user_input
and "SELECT " not in user_input
and "FROM " not in user_input
and "DELETE " not in user_input
and '"' not in user_input
and ";" not in user_input
and "=" not in user_input
and ">" not in user_input
and "<" not in user_input):
pass
else:
exit()
编辑:由于存在一些混乱,这应该是正确的缩进: https:// i.sstatic.net/SOpip.png 这是 Pycharm 认为正确的一个 https://i.sstatic.net/z5oUr.png。除非我弄错了(可能是这种情况!)。
This post's answer suggests PEP 8: E128 requires spaces on the lines following the first one when they're all wrapped inside parentheses. However, with an if
statement this doesn't seem to be the case. You can see that the first three lines do not have a warning and the following do because they do have a space:
Am I missing something? I am using Pycharm Community edition if that helps.
Code used:
def main(user_input):
if (";" not in user_input
and "DROP " not in user_input
and "SELECT " not in user_input
and "FROM " not in user_input
and "DELETE " not in user_input
and '"' not in user_input
and ";" not in user_input
and "=" not in user_input
and ">" not in user_input
and "<" not in user_input):
pass
else:
exit()
EDIT: as there is a bit of confusion, this should be the correct indentation: https://i.sstatic.net/SOpip.png and this is the one Pycharm thinks is the correct one https://i.sstatic.net/z5oUr.png. Unless I'm mistaken (could be the case!).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
PEP-8 注意到,
if (
提供了一个自然的 4 个空格缩进,允许在括号之后开始延续:您的检查器显然没有请注意您是否
改为写入,但是,如果您确实使用该缩进,则必须继续使用相同的缩进您的
FROM
行是。第一条偏离的线这种情况很常见,PEP 甚至提供了一个链接到 本段:
PEP-8 notes that
if (
provides a natural 4-space indentation which allows a continuation to begin after the parenthesis:Your checker apparently does not care if you write
instead, but, if you do use that indentation, you have to continue to use the same indentation. Your
FROM
line is the first line to deviate from that indentation.This is common enough that the PEP even provides an anchor to link to this paragraph:
带有“FROM”的行比之前的行缩进1个空格。这就是触发警告的原因。
The line with "FROM" is indented 1 space more than the line before. That's what's triggering the warning.