-
Notifications
You must be signed in to change notification settings - Fork 748
Description
The current behavior of E225 / E252 differs between regular function parameters and function type-parameters.
- When a function parameter has a default, but no upper bound, there are no spaces expected
- When a function type-parameters has a default, but no upper bound, there are spaces expected
It seems this was introduced in #1286 without any discussion. I believe a good argument can be made that "=" for type-parameters should follow the same spacing rules as "=" for regular function parameters1, but of course that's just my opinion.
It would be helpful if this error code could be split into one for function parameters and one for type-parameters, so users can selectively disable the different spacing rules for type-parameters.
# fmt: off
def foo[
X=int, # E225,E252: missing whitespace around operator / parameter equals
Y = int, # OK
Z: object=int, # E225,E252: missing whitespace around operator / parameter equals
W: object = int, # OK
](
x=int, # OK
y = int, # E251 unexpected spaces around keyword / parameter equals
z: object=int, # E252 missing whitespace around parameter equal
w: object = int, # OK
): ...$ pycodestyle tmp.py
tmp.py:3:6: E225 missing whitespace around operator
tmp.py:3:6: E252 missing whitespace around parameter equals
tmp.py:3:7: E252 missing whitespace around parameter equals
tmp.py:5:14: E225 missing whitespace around operator
tmp.py:5:14: E252 missing whitespace around parameter equals
tmp.py:5:15: E252 missing whitespace around parameter equals
tmp.py:9:6: E251 unexpected spaces around keyword / parameter equals
tmp.py:9:8: E251 unexpected spaces around keyword / parameter equals
tmp.py:10:14: E252 missing whitespace around parameter equals
tmp.py:10:15: E252 missing whitespace around parameter equals
Footnotes
-
IMO, the spaces do not increase readability when no upper bound is given, but eat up valuable space. Especially when writing overloads, readability tends to degrade a lot when one overload no longer fits on a single line. ↩