r/Python • • 11m ago

Discussion PEP 671 – Syntax for late-bound function argument defaults

https://peps.python.org/pep-0671/

The PEP was originally proposed in October 2021 but didnt get much traction. Through some discussions on the python discuss the author picked it up again and reproposed it for 3.17

It proposes a new syntax argument => late_bound_default()

def add_item(item, target=>[]):
def bisect_right(a, x, lo=0, hi=>len(a), *, key=None):

for late binding of argument defaults. This would allow avoiding the common mutable default argument trap and would allow for defaults to refer to previous arguments as seen in the biset_right example above.

Discussion can be found here: https://discuss.python.org/t/pep-671-syntax-for-late-bound-function-argument-defaults/110297

Note: I am not the PEP author

3 Upvotes

0 comments sorted by