zserio icon indicating copy to clipboard operation
zserio copied to clipboard

Improve Python code generation according to the PEP-8 conventions

Open aminkr opened this issue 4 years ago • 1 comments

I‌ have used zserio==2.3.0 to generate Python sources. It seems it's not fully compatible with the PEP-8 style. A few remarks:

  • PEP 8: E302 expected 2 blank lines, found 1 (between importing modules and class definition)

  • Naming like bitsizeof (instead of bit_sizeof) or bitposition (bit_position)

  • The method may be 'static' ( we do not use staticmethod decorator !!!)

  • Unused parameters also can be found like:

    def bitsizeof(self, _bitposition: int = 0) -> int:
           return 8
    
  • PEP 8: E714 test for object identity should be 'is not': This is a kind of anti-pattern in python

    return not self._request_num_sent_ is None

    The best practice is to use something like:

    return self._request_num_sent_ is not None

All of the issues can be found by running pycodestyle * or pycodestyle --statistics -qq *.

aminkr avatar Apr 12 '21 10:04 aminkr

Thanks a lot for reporting this.

Actually, we use only pylint and mypy. We should add pycodestyle to CI as well to be able to catch all such problems as you wrote. Good idea.

mikir avatar Apr 12 '21 11:04 mikir