我正在尝试解决对Firefox UI GitHub存储库的拉取请求后Travis构建生成的PEP8错误。我已经能够使用pep8
库在本地重现这些错误。具体来说,文件中的以下行超出了99个字符的限制:
Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open and len(self.autocomplete_results.visible_results) > 1))
通过pep8
运行它时产生的错误由以下给出:
$ pep8 --max-line-length=99 --exclude=client firefox_ui_tests/functional/locationbar/test_access_locationbar.py
firefox_ui_tests/functional/locationbar/test_access_locationbar.py:51:100: E501 line too long (136 > 99 characters)
该行从Marionette Python客户端调用Wait().until()
方法。以前,此行实际上是两个单独的行:
Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open)
Wait(self.marionette).until(lambda _: len(self.autocomplete_results.visible_results) > 1)
回购经理建议我将这两行合并为一,但这延长了结果行的长度,从而导致PEP8错误。
我可以将其更改回原来的样子,但是可以通过任何方式格式化或缩进该行,以免引起此PEP8错误。
提前致谢。
python大神给出的解决方案
是;
Wait(self.marionette).until(
lambda _: (
self.autocomplete_results.is_open and
len(self.autocomplete_results.visible_results) > 1
)
)
校验:
$ pep8 --max-line-length=99 --exclude=client foo.py
请救援! 🙂