简体   繁体   English

Python-解决PEP8错误

[英]Python - Resolving PEP8 errors

I'm trying to resolve PEP8 errors that were generated by a Travis build after a pull request to the Firefox UI GitHub repo. 我正在尝试解决对Firefox UI GitHub存储库的拉取请求后Travis构建生成的PEP8错误。 I've been able to reproduce these errors locally using the pep8 library. 我已经可以使用pep8库在本地重现这些错误。 Specifically I have the following line in a file which exceeds the 99 character limit: 具体来说,文件中的以下行超出了99个字符的限制:

Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open and len(self.autocomplete_results.visible_results) > 1))

The error it produces on running it through pep8 is given by: 通过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)

The line calls the Wait().until() method from the Marionette Python client. 该行从Marionette Python客户端调用Wait().until()方法。 Previously this line was actually two separate lines: 以前,此行实际上是两个单独的行:

Wait(self.marionette).until(lambda _: self.autocomplete_results.is_open)
Wait(self.marionette).until(lambda _: len(self.autocomplete_results.visible_results) > 1)

The repo manager advised me to combine these two lines into one, but this has extended the length of the resulting line, causing the PEP8 error. 回购经理建议我将这两行合并为一,但这延长了结果行的长度,从而导致PEP8错误。

I could change it back to the way it was, but is there any way of formatting or indenting the line so that it does not cause this PEP8 error. 我可以将其更改回原来的样子,但是可以通过任何方式格式化或缩进该行,以免引起此PEP8错误。

Thanks in advance. 提前致谢。

Yes; 是;

Wait(self.marionette).until(
    lambda _: (
        self.autocomplete_results.is_open and
        len(self.autocomplete_results.visible_results) > 1
    )
)

Check: 校验:

$ pep8 --max-line-length=99 --exclude=client foo.py

parens to the rescue! 请救援! :) :)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM