PEP 0008: Clarify self-contradictory =-spacing rules (#820)

Previously, the PEP contained roughly the following three rules, in sequence:

1. Never use spaces around `=` when used to indicate a parameter default
2. Something unrelated
3. DO use spaces around `=` when used to indicate a parameter default if there is also a parameter annotation present

This commit attempts to clarify this part of the PEP by:
* Combining the first and third rules listed above into a single rule that addresses both annotated and unannotated parameters
* Rephrasing the first rule to indicate that it applies only to unannotated parameters, to eliminate the logical contradiction
This commit is contained in:
Mark Amery 2018-10-29 17:52:27 +00:00 committed by Barry Warsaw
parent cd1efca559
commit acda0d1dde
1 changed files with 17 additions and 16 deletions

View File

@ -552,19 +552,6 @@ Other Recommendations
hypot2 = x * x + y * y hypot2 = x * x + y * y
c = (a + b) * (a - b) c = (a + b) * (a - b)
- Don't use spaces around the ``=`` sign when used to indicate a
keyword argument or a default parameter value.
Yes::
def complex(real, imag=0.0):
return magic(r=real, i=imag)
No::
def complex(real, imag = 0.0):
return magic(r = real, i = imag)
- Function annotations should use the normal rules for colons and - Function annotations should use the normal rules for colons and
always have spaces around the ``->`` arrow if present. (See always have spaces around the ``->`` arrow if present. (See
`Function Annotations`_ below for more about function annotations.) `Function Annotations`_ below for more about function annotations.)
@ -579,9 +566,23 @@ Other Recommendations
def munge(input:AnyStr): ... def munge(input:AnyStr): ...
def munge()->PosInt: ... def munge()->PosInt: ...
- When combining an argument annotation with a default value, use - Don't use spaces around the ``=`` sign when used to indicate a
spaces around the ``=`` sign (but only for those arguments that have keyword argument, or when used to indicate a default value for an
both an annotation and a default). *unannotated* function parameter.
Yes::
def complex(real, imag=0.0):
return magic(r=real, i=imag)
No::
def complex(real, imag = 0.0):
return magic(r = real, i = imag)
When combining an argument annotation with a default value, however, do use
spaces around the ``=`` sign:
Yes:: Yes::