From a53dcc0e6159cd337ebe103ea9df85c47d1917c2 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Fri, 20 Nov 2026 07:23:19 +1100 Subject: [PATCH 1/2] Polish up PEP 671 for reposting --- peps/pep-0671.rst | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/peps/pep-0671.rst b/peps/pep-0671.rst index c0afd385039..18db8f923d6 100644 --- a/peps/pep-0671.rst +++ b/peps/pep-0671.rst @@ -5,7 +5,7 @@ Discussions-To: https://mail.python.org/archives/list/python-ideas@python.org/th Status: Draft Type: Standards Track Created: 24-Oct-2021 -Python-Version: 3.12 +Python-Version: 3.17 Post-History: `24-Oct-2021 `__, `01-Dec-2021 `__ @@ -34,6 +34,7 @@ Currently-legal idioms for this include:: hi = len(a) # Also well known: Use a unique custom sentinel object + # This could equivalently be sentinel("_USE_GLOBAL_DEFAULT") _USE_GLOBAL_DEFAULT = object() def connect(timeout=_USE_GLOBAL_DEFAULT): if timeout is _USE_GLOBAL_DEFAULT: @@ -70,13 +71,13 @@ scope in which the function was defined (as are early-bound defaults). This 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. +to previously-defined values. Order is defined by the function definition, +regardless of the order in which keyword arguments may be passed. def prevref(word="foo", a=>len(word), b=>a//2): # Valid def selfref(spam=>spam): # UnboundLocalError - def spaminate(sausage=>eggs + 1, eggs=>sausage - 1): # Confusing, don't do this - def frob(n=>len(items), items=[]): # See below + def spaminate(sausage=>eggs + 1, eggs=>sausage - 1): # Don't do this + def frob(n=>len(items), items=[]): # Don't do this (but see below) Evaluation order is left-to-right; however, implementations MAY choose to do so in two separate passes, first for all passed arguments and early-bound defaults, @@ -130,18 +131,9 @@ cover the important distinction here (and the fact that they are similar). Interaction with other proposals ================================ -:pep:`661` attempts to solve one of the same problems as this does. It seeks to -improve the documentation of sentinel values in default arguments, where this -proposal seeks to remove the need for sentinels in many common cases. :pep:`661` -is able to improve documentation in arbitrarily complicated functions (it -cites ``traceback.print_exception`` as its primary motivation, which has two -arguments which must both-or-neither be specified); on the other hand, many -of the common cases would no longer need sentinels if the true default could -be defined by the function. Additionally, dedicated sentinel objects can be -used as dictionary lookup keys, where :pep:`671` does not apply. - -A generic system for deferred evaluation has been proposed at times (not to be -confused with :pep:`563` and :pep:`649` which are specific to annotations). +A generic system for deferred evaluation has been proposed at times (in addition +to `function annotations `__ +which can be evaluated lazily). While it may seem, on the surface, that late-bound argument defaults are of a similar nature, they are in fact unrelated and orthogonal ideas, and both could be of value to the language. The acceptance or rejection of this proposal would From 85c9a064ee64bff8c1168815b95a20b4cccae1e6 Mon Sep 17 00:00:00 2001 From: Chris Angelico Date: Fri, 20 Nov 2026 20:10:49 +1100 Subject: [PATCH 2/2] Fix formatting --- peps/pep-0671.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/peps/pep-0671.rst b/peps/pep-0671.rst index 18db8f923d6..6a200afaee8 100644 --- a/peps/pep-0671.rst +++ b/peps/pep-0671.rst @@ -74,6 +74,8 @@ Multiple late-bound arguments are evaluated from left to right, and can refer to previously-defined values. Order is defined by the function definition, regardless of the order in which keyword arguments may be passed. +:: + def prevref(word="foo", a=>len(word), b=>a//2): # Valid def selfref(spam=>spam): # UnboundLocalError def spaminate(sausage=>eggs + 1, eggs=>sausage - 1): # Don't do this