Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Questionable "bad-whitespace" for function annotations with default values #238

Closed
pylint-bot opened this issue May 7, 2014 · 7 comments
Labels

Comments

@pylint-bot
Copy link

Originally reported by: Antony Lee (BitBucket: anntzer, GitHub: @anntzer?)


Both http://legacy.python.org/dev/peps/pep-3107/ and https://docs.python.org/3/tutorial/controlflow.html#function-annotations put spaces around the = for default values when an argument has an annotation:

#!python
def f(x: int = 1): pass
# compare with
def f(x: int=1): pass

I also think that the second option looks weird as I tend to parse it as x: (int=1), not (x: int) = 1. Well, perhaps the syntax could have been better but that's what we have now.

But Pylint currently triggers a bad-whitespace warning for the first option.


@pylint-bot
Copy link
Author

Original comment by Antony Lee (BitBucket: anntzer, GitHub: @anntzer?):


By the way, the official PEP8 has been updated to mandate the version with spaces.

@dvemnt
Copy link

dvemnt commented Mar 30, 2016

1

@junmo-kim
Copy link

https://www.python.org/dev/peps/pep-0008/#other-recommendations
Updated PEP8 recommends whitespace around equal sign in this situation.

When combining an argument annotation with a default value, use spaces around the = sign (but only for those arguments that have both an annotation and a default).

  • Yes:
def munge(sep: AnyStr = None): ...
def munge(input: AnyStr, sep: AnyStr = None, limit=1000): ...
  • No:
def munge(input: AnyStr=None): ...
def munge(input: AnyStr, limit = 1000): ...

@petrpulc
Copy link
Contributor

Adressed in #1229

@PCManticore
Copy link
Contributor

Thanks @petrpulc

@petrpulc
Copy link
Contributor

Hello again.
It works but is far from perfect as I see now...
Take for example:

import datetime
def foo(date: datetime.date = None)

which will now still result in bad-whitespace.

While the "regular" type hints work now (yet are not checked against imported names), this is virtually uncheckable. Should I resign and add the period as an ignored token; or would it be even better to not check the contents of the annotation at all?

@PCManticore
Copy link
Contributor

@petrpulc There is already a PR for that: #1430.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants