1

I reduced the issue to the following minimal example:

"""Example"""
def         answer():
    """Answer"""
    return 42

Pylint doesn't give any "bad whitespace" warning:

Your code has been rated at 10.00/10 (previous run: 10.00/10, +0.00)

Pylint does give warnings for spaces in front of brackets and trailing whitespace or newlines and so on. Why are there no warnings in this case?

finefoot
  • 9,914
  • 7
  • 59
  • 102
  • Neither does it give a warning for `return 42` if you put like a gazillion tabs between them. It's because that's not officially part of the pep8 standard (and whitespacing like that can be used to make clearer code divisions, e.g. lining stuff up). – Green Cloak Guy Jun 17 '19 at 21:29
  • Not necessarily "after a keyword", but similar principles apply when you're aligning a dict literal (putting all the text into columns). Or other multi-line expressions that you want to align with each other. – Green Cloak Guy Aug 03 '19 at 03:46

2 Answers2

1

Whitespaces can be used to:

In case of return, you would have an error if its indentation was incoherent with other elements in its block:

for x in p:
        r.append(l[i:i+1] + x)
    return r                # error: inconsistent dedent

But in your case, it is alone in its def block.
And none of the Pylint C0326 would apply here.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Yes, wrong indentation is obviously a whole other issue - that would change the behavior of the code, maybe even result in an error. I'm talking more about "unnecessary" whitespace. Maybe the question should better have been **why** isn't there a rule in http://pylint-messages.wikidot.com/messages:c0326 to disallow `def......f():` when there is a rule about `def f......():`? (Had to use dots instead of spaces here in the comments.) I don't understand why there is a rule about the latter but not about the first example. – finefoot Aug 02 '19 at 17:42
  • @finefoot I suppose because the former allows for alignment (unlikely with def, but not impossible. https://votecharlie.com/blog/2016/04/alignment-in-python-code.html), while the latter means parsing a function name would fail. – VonC Aug 03 '19 at 04:04
1

I recomend you to use Flake8 in your case

Multiple spaces after keyword (E271)

If you are interesting in Flake8, this is the page of all the code error that Flake8 has

Axel Anaya
  • 122
  • 9