Python - Resolving PEP8 errors

173 views Asked by At

I'm trying to resolve PEP8 errors that were generated by a Travis build after a pull request to the Firefox UI GitHub repo. I've been able to reproduce these errors locally using the pep8 library. Specifically I have the following line in a file which exceeds the 99 character limit:

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 --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. 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.

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.

Thanks in advance.

1

There are 1 answers

0
James Mills On BEST ANSWER

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! :)