PEP 671: Clarify some points about the current options
This commit is contained in:
parent
c0b6e938f1
commit
213776f5f1
19
pep-0671.rst
19
pep-0671.rst
|
@ -71,14 +71,14 @@ allows the expression to refer to other arguments.
|
||||||
|
|
||||||
Multiple late-bound arguments are evaluated from left to right, and can refer
|
Multiple late-bound arguments are evaluated from left to right, and can refer
|
||||||
to previously-defined values. Order is defined by the function, regardless of
|
to previously-defined values. Order is defined by the function, regardless of
|
||||||
the order in which keyword arguments may be passed. Using names of other
|
the order in which keyword arguments may be passed. Using names of later
|
||||||
arguments is an error. It is implementation-defined whether this is a syntax
|
arguments should not be relied upon, and while this MAY work in some Python
|
||||||
error or a run-time error, and implementations are free to be more permissive,
|
implementations, it should be considered dubious::
|
||||||
but this should not be relied upon.
|
|
||||||
|
|
||||||
def spaminate(sausage=>eggs + 1, eggs=>sausage - 1): # Error
|
def prevref(word="foo", a=>len(word), b=>a//2): # Valid
|
||||||
def selfref(spam=>spam): # Error
|
def selfref(spam=>spam): # Highly likely to give an error
|
||||||
def frob(n=>len(items), items=[]): # Error
|
def spaminate(sausage=>eggs + 1, eggs=>sausage - 1): # Confusing, may fail
|
||||||
|
def frob(n=>len(items), items=[]): # May fail, may succeed
|
||||||
|
|
||||||
|
|
||||||
Choice of spelling
|
Choice of spelling
|
||||||
|
@ -87,15 +87,18 @@ Choice of spelling
|
||||||
Our chief syntax proposal is ``name=>expression`` -- our two syntax proposals
|
Our chief syntax proposal is ``name=>expression`` -- our two syntax proposals
|
||||||
... ahem. Amongst our potential syntaxes are::
|
... ahem. Amongst our potential syntaxes are::
|
||||||
|
|
||||||
|
# Preferred options: adorn the equals sign (approximate preference order)
|
||||||
def bisect(a, hi=>len(a)):
|
def bisect(a, hi=>len(a)):
|
||||||
def bisect(a, hi=:len(a)):
|
def bisect(a, hi=:len(a)):
|
||||||
def bisect(a, hi:=len(a)):
|
def bisect(a, hi:=len(a)):
|
||||||
def bisect(a, hi?=len(a)):
|
def bisect(a, hi?=len(a)):
|
||||||
def bisect(a, hi!=len(a)):
|
def bisect(a, hi!=len(a)):
|
||||||
def bisect(a, hi=\len(a)):
|
def bisect(a, hi=\len(a)):
|
||||||
def bisect(a, hi=`len(a)`):
|
|
||||||
def bisect(a, hi=@len(a)):
|
def bisect(a, hi=@len(a)):
|
||||||
|
# Less preferred option: adorn the variable name
|
||||||
def bisect(a, @hi=len(a)):
|
def bisect(a, @hi=len(a)):
|
||||||
|
# Less preferred option: adorn the expression
|
||||||
|
def bisect(a, hi=`len(a)`):
|
||||||
|
|
||||||
Since default arguments behave largely the same whether they're early or late
|
Since default arguments behave largely the same whether they're early or late
|
||||||
bound, the preferred syntax is very similar to the existing early-bind syntax.
|
bound, the preferred syntax is very similar to the existing early-bind syntax.
|
||||||
|
|
Loading…
Reference in New Issue