py-evm icon indicating copy to clipboard operation
py-evm copied to clipboard

Tighten linting rules to catch white space inconsistencies

Open cburgdorf opened this issue 7 years ago • 4 comments

What is wrong?

Our current linting rules don't catch certain inconsistencies around the handling of white space. Notice the mix of white space / no white space around the = symbol in the following code.


    def __init__(
        self,
        number: int,
        transaction_root: bytes = EMPTY_SHA3,
        coinbase: bytes=ZERO_ADDRESS,
          ) -> None:
        ...

Our current flake8 linting doesn't catch this. The official style guide favors to use the spaces around the = symbol in this case which is enforceable using using pylint.

How can it be fixed

  • switch to black formatter (See discussion #476)
  • add a pylint check
  • write a flake8 plugin (maybe?)

cburgdorf avatar Mar 19 '18 13:03 cburgdorf

@cburgdorf we are currently using the flake8 version 3.5.0. But the most latest version of flake8 which is 3.6.0 captures these missing spaces. Should I go with upgrading the version to 3.6.0, and even add spaces wherever they are missing?

Bhargavasomu avatar Dec 22 '18 11:12 Bhargavasomu

But on the contrary, it still doesn't support detecting the type hinting syntax as of now in 3.6.0. Can find the corresponding comment here. It basically sees the colon in the function type hints and throws a Syntax Error. Hence we should wait till this issue is resolved probably.

Bhargavasomu avatar Dec 22 '18 11:12 Bhargavasomu

@Bhargavasomu type hints work fine, it's type comments that don't work in the issue you've linked.

$ cat t.py 
x: int = 5


class C:
    x: int = 5

    def f(self, x: int = 5) -> int:
        pass
$ flake8 --version
3.6.0 (mccabe: 0.6.1, pycodestyle: 2.4.0, pyflakes: 2.0.0) CPython 3.6.7 on Linux
$ flake8 t.py 
$ echo $?
0

asottile avatar Jan 01 '19 07:01 asottile

@Bhargavasomu I'm :+1: on upgrading for this. ethereum/trinity repo should be free of comment based type hints if you wanted to start there.

pipermerriam avatar Jan 02 '19 19:01 pipermerriam