Skip to content

Commit

Permalink
PEP 671: Clarify some points about the current options
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Nov 10, 2021
1 parent c0b6e93 commit 213776f
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions pep-0671.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 an error. It is implementation-defined whether this is a syntax
error or a run-time error, and implementations are free to be more permissive,
but this should not be relied upon.
the order in which keyword arguments may be passed. Using names of later
arguments should not be relied upon, and while this MAY work in some Python
implementations, it should be considered dubious::

def spaminate(sausage=>eggs + 1, eggs=>sausage - 1): # Error
def selfref(spam=>spam): # Error
def frob(n=>len(items), items=[]): # Error
def prevref(word="foo", a=>len(word), b=>a//2): # Valid
def selfref(spam=>spam): # Highly likely to give an 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
Expand All @@ -87,15 +87,18 @@ Choice of spelling
Our chief syntax proposal is ``name=>expression`` -- our two syntax proposals
... 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)):
# Less preferred option: adorn the variable name
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
bound, the preferred syntax is very similar to the existing early-bind syntax.
Expand Down

0 comments on commit 213776f

Please sign in to comment.