Skip to content

Commit

Permalink
PEP 671: Change recommendation from permissive to strict
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Oct 24, 2021
1 parent e61f18a commit cc75aee
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions pep-0671.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
==========
Expand Down

0 comments on commit cc75aee

Please sign in to comment.