W391 表示文件末尾应该有一个(并且只有一个)空白行。但是,当文件末尾至少有一个换行符时,flake8 会报告错误:
$ cat /tmp/test.py
def hello():
print('hello')
hello()
$ hexdump -C /tmp/test.py
00000000 64 65 66 20 68 65 6c 6c 6f 28 29 3a 0a 20 20 20 |def hello():. |
00000010 20 70 72 69 6e 74 28 27 68 65 6c 6c 6f 27 29 0a | print('hello').|
00000020 0a 0a 68 65 6c 6c 6f 28 29 0a 0a |..hello()..|
0000002b
您可以在上面看到实际上文件末尾只有一个空行(0a
is \n
)。但是,当我运行 flake8 时,我收到 W391 错误:
$ flake8 /tmp/test.py
/tmp/test.py:6:1: W391 blank line at end of file
这是为什么?