Skip to content

Conversation

@dciborow
Copy link
Contributor

@dciborow dciborow commented Mar 2, 2023

When using black to autoformat an extension one flake8 rule fails on a rule which does not follow pep8. W503 is disabled by default, but because the .flake8 files are using "ignore" instead of "extend-ignore", W503 is enabled in our ruleset. The maintainer of flake8 explained here I recommend that we disable this rule, so that people may follow pep8 while also being able to use black to autoformat their code.

Line break occurred before a binary operator (W503)

This rule goes against the PEP 8 recommended style, which was changed on April 16th, 2016 in [this commit](https://github.com/python/peps/commit/c59c4376ad233a62ca4b3a6060c81368bd21e85b). The tool [will soon be updated](https://github.com/PyCQA/pycodestyle/pull/502) to recommend the opposite: line breaks should occur before the binary operator because it keeps all operators aligned.

Code Before Autoformat

    def is_equal(self, other):
        return (
            self.__class__ == other.__class__ and
            self.type == other.type and
            self.name == other.name and
            self.email == other.email and
            self.phone == other.phone and
            self.uri == other.uri
        )

Code After Autoformat

    def is_equal(self, other):
        return (
            self.__class__ == other.__class__
            and self.type == other.type
            and self.name == other.name
            and self.email == other.email
            and self.phone == other.phone
            and self.uri == other.uri
        )

Flake8 Output

Running flake8 on extensions...
/workspaces/partnercenter-cli-extension/partnercenter/azext_partnercenter/models/listing_contact.py:29:13: W503 line break before binary operator
/workspaces/partnercenter-cli-extension/partnercenter/azext_partnercenter/models/listing_contact.py:30:13: W503 line break before binary operator
/workspaces/partnercenter-cli-extension/partnercenter/azext_partnercenter/models/listing_contact.py:31:13: W503 line break before binary operator
/workspaces/partnercenter-cli-extension/partnercenter/azext_partnercenter/models/listing_contact.py:32:13: W503 line break before binary operator
/workspaces/partnercenter-cli-extension/partnercenter/azext_partnercenter/models/listing_contact.py:33:13: W503 line break before binary operator
5     W503 line break before binary operator

@dciborow dciborow changed the title Disable flake8 w503 fix: Disable flake8 w503 Mar 2, 2023
@wangzelin007 wangzelin007 self-assigned this Mar 3, 2023
@wangzelin007 wangzelin007 added the CI Continuous Integration label Mar 3, 2023
@wangzelin007
Copy link
Member

Personally, I prefer this format:

    def is_equal(self, other):
        return (
            self.__class__ == other.__class__
            and self.type == other.type
            and self.name == other.name
            and self.email == other.email
            and self.phone == other.phone
            and self.uri == other.uri
        )

@wangzelin007 wangzelin007 merged commit 35bf6e5 into Azure:dev Mar 3, 2023
@dciborow dciborow deleted the dciborow/flake8-w503 branch March 3, 2023 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Continuous Integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants