PEP 671: Change recommendation from permissive to strict
This commit is contained in:
parent
e61f18a104
commit
cc75aee2a5
20
pep-0671.rst
20
pep-0671.rst
|
@ -68,13 +68,14 @@ Notably, the expression is evaluated in the function's run-time scope, NOT the
|
|||
scope in which the function was defined (as are early-bound defaults). This
|
||||
allows the expression to refer to other arguments.
|
||||
|
||||
Self-referential expressions will result in UnboundLocalError::
|
||||
|
||||
def spam(eggs=>eggs): # Nope
|
||||
|
||||
Multiple late-bound arguments are evaluated from left to right, and can refer
|
||||
to previously-calculated values. Order is defined by the function, regardless
|
||||
of the order in which keyword arguments may be passed.
|
||||
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
|
||||
arguments is a SyntaxError at function definition time::
|
||||
|
||||
def spaminate(sausage=>eggs + 1, eggs=>sausage - 1): # SyntaxError
|
||||
def selfref(spam=>spam): # SyntaxError
|
||||
def frob(n=>len(items), items=[]): # SyntaxError
|
||||
|
||||
|
||||
Choice of spelling
|
||||
|
@ -131,6 +132,13 @@ Open Issues
|
|||
- annotations? They go before the default, so is there any way an anno could
|
||||
want to end with ``=>``?
|
||||
|
||||
- Rather than banning future refs, these could be permitted, at the price of
|
||||
harder-to-explain semantics. Arguments would be resolved first with those
|
||||
passed and those with early-bound defaults, and then late-bound ones would
|
||||
be evaluated, left-to-right; the consequences for getting it wrong would
|
||||
then be UnboundLocalError at call time, rather than SyntaxError from the
|
||||
function definition.
|
||||
|
||||
|
||||
References
|
||||
==========
|
||||
|
|
Loading…
Reference in New Issue