Pycodestyle: E252 raised on annotated expression-based defaults involving equals

Created on 15 Apr 2018  路  4Comments  路  Source: PyCQA/pycodestyle

E252 is being raised on what look to be valid annotated, expression-based arguments which contain equals.

Example:

# foo.py


def _default(name: str) -> float:

    defaults = {'f': 100.0}

    return defaults.get(name, 0.0)


def f(x, y: float = _default(name='f')) -> float:
    """Test function."""

    return x + y
$ pycodestyle -v foo.py
user configuration: /Users/josh/.config/pycodestyle
checking foo.py
/tmp/foo.py:11:34: E252 missing whitespace around parameter equals
/tmp/foo.py:11:35: E252 missing whitespace around parameter equals

$ pycodestyle --version
2.4.0

$ cat ~/.config/pycodestyle
[pycodestyle]
max-line-length = 160

Most helpful comment

Any chance of a release including a fix for this? I'm coming across this more and more. Thanks.

All 4 comments

@taion
looks like commit: d9efb8f46220dc24f74cb8e0f963786d47deecdc missing something since it says:

Don't use spaces around the '=' sign when used to indicate a
keyword argument or a default parameter value, except when using a type annotation.

Definitely looks like my bug. Let me see.

Any chance of a release including a fix for this? I'm coming across this more and more. Thanks.

Yes please, a release!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

lzkelley picture lzkelley  路  7Comments

bulletmark picture bulletmark  路  9Comments

daspecster picture daspecster  路  9Comments

asottile picture asottile  路  8Comments

b4hand picture b4hand  路  4Comments