
On 24 Oct 2021, at 01:13, Chris Angelico <rosuav@gmail.com> wrote:
Specification =============
Function default arguments can be defined using the new ``=>`` notation::
def bisect_right(a, x, lo=0, hi=>len(a), *, key=None): def connect(timeout=>default_timeout): def add_item(item, target=>[]):
The expression is saved in its source code form for the purpose of inspection, and bytecode to evaluate it is prepended to the function's body.
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.
Clarification please: What is the bytecode that will be generated? Does the bytecode only run the default code if the argument is missing? And missing is not the same as is None? Also have you add the @var=default suggestion from Stephen to the syntax options. I'm +1 on the @ syntax as it is easier to pick up on and the other reasons that Stephen provided. Barry