1

I often have code which for readability reasons I would like to indent in a column-wise structure. For example:

props = {
    'name'    : foo(df, 'name'),
    'address' : foo(df, 'address'),
    'phone'   : foo(df, 'phone'),
    'surname' : foo(df, 'surname'),
    'age'     : foo(df, 'age'),
    'height'  : foo(df, 'height'),
    'weight'  : foo(df, 'weight'),
    ...
}

This of course results in PEP8 warning due to the extra white spaces, which hurts our style checkers & formatters.

Is there a way to make the column structure and PEP8 live in peace somehow?

Elad Weiss
  • 3,662
  • 3
  • 22
  • 50
  • 1
    PEP 8 is a convention. In your case it is either PEP8 or your style. You have to make that decision. – Klaus D. May 20 '19 at 11:35
  • 1
    Every style checker has mechanisms to disable warnings or formatting for a particular block of code or file (e.g. [How to disable a pep8 error in a specific file?](https://stackoverflow.com/q/18444840)). You may also be able to configure it to disable some rule, as proposed. It depends on what tool exactly you are using. – jdehesa May 20 '19 at 11:38
  • 1
    I believe there is no rule about whitespace following a colon though. Maybe add the extra spaces after the colon instead. – spejsy May 20 '19 at 11:41

2 Answers2

1

You can disable a particular rule in PEP8 config:

[pycodestyle]
count = False
ignore = E226,E302,E41  <-------------- here I am!
max-line-length = 160
statistics = True

Here are error codes to ignore.


If you don't want do disable a rule everywhere, you can add #noqa comment in the end of the line you don't want to be checked. All PEP8 errors in that line will be disabled.

If you are using several linters, you should check and re-config them too.

vurmux
  • 9,420
  • 3
  • 25
  • 45
0

You could add the extraneous whitespace after the colon instead, like below:

props = {
    'name':     foo(df, 'name'),
    'address':  foo(df, 'address'),
    'phone':    foo(df, 'phone'),
    'surname':  foo(df, 'surname'),
    'age':      foo(df, 'age'),
    'height':   foo(df, 'height'),
    'weight':   foo(df, 'weight'),
    ...
}
spejsy
  • 123
  • 8