flake8: E743 函数定义不明确 'O'
flake8: E743 ambiguous function definition 'O'
当我在一个只有一行的文件上 运行 flake8 时:def O(): pass
我得到了以下错误,尽管函数 运行 很好:
/tmp/a.py:1:5: E743 ambiguous function definition 'O'
为什么 flake8 失败了?为什么我不只是收到警告?
Do not define functions named 'l', 'o', or 'i' (E743)
Functions named I
, O
, and l
can be very hard to read. This is because the letter I
and
the letter l
are easily confused, and the letter O
and the number 0
can be easily confused.
Change the names of these functions to something more descriptive.
Additional links
- https://www.python.org/dev/peps/pep-0008/#names-to-avoid
flake8 is a utility for enforcing pep8 style consistency across Python projects, and according to pep8 function naming conventions: Function names should be lowercase, with words separated by underscores as necessary to improve readability.
如果你想让 flake8 忽略这个特定的错误(这有悖于 linting 的目的)要么将它添加到你的 setup.cfg
文件中:
[flake8]
ignore = E743
或运行它使用以下选项:flake8 --ignore=E743
但是,如果您只希望 flake8 不会失败并且只显示警告,则必须 运行 使用 --exit-zero
:
flake8 --exit-zero
当我在一个只有一行的文件上 运行 flake8 时:def O(): pass
我得到了以下错误,尽管函数 运行 很好:
/tmp/a.py:1:5: E743 ambiguous function definition 'O'
为什么 flake8 失败了?为什么我不只是收到警告?
Do not define functions named 'l', 'o', or 'i' (E743)
Functions namedI
,O
, andl
can be very hard to read. This is because the letterI
and the letterl
are easily confused, and the letterO
and the number0
can be easily confused.Change the names of these functions to something more descriptive.
Additional links
- https://www.python.org/dev/peps/pep-0008/#names-to-avoid
flake8 is a utility for enforcing pep8 style consistency across Python projects, and according to pep8 function naming conventions: Function names should be lowercase, with words separated by underscores as necessary to improve readability.
如果你想让 flake8 忽略这个特定的错误(这有悖于 linting 的目的)要么将它添加到你的 setup.cfg
文件中:
[flake8]
ignore = E743
或运行它使用以下选项:flake8 --ignore=E743
但是,如果您只希望 flake8 不会失败并且只显示警告,则必须 运行 使用 --exit-zero
:
flake8 --exit-zero