On Fri, Dec 3, 2021 at 2:11 AM Rob Cliffe via Python-ideas <python-ideas@python.org> wrote:
On 02/12/2021 14:47, Steven D'Aprano wrote:
def f(x=...): ... try: print("You passed x as", x) ... except UnboundLocalError: print("You didn't pass x") ... f.__defaults_extra__ = ("n/a",) f(42) You passed x as 42 f() You didn't pass x That is absolutely an abomination. If your implementation has the side-effect that setting a regular early-bound default to Ellipsis makes
On Thu, Dec 02, 2021 at 11:00:33PM +1100, Chris Angelico wrote: I'm still unsure whether this is a cool feature or an utter abomination: the parameter unable to retrieve the default, then the implementation is fatally broken.
It absolutely is not a feature.
It's backward incompatible:
15:03:04 R:\>python Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:20:19) [MSC v.1925 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information.
def f(x=...): ... try: print("You passed x as", x) ... except UnboundLocalError: print("You didn't pass x") ... f() You passed x as Ellipsis
So I must agree with Steven that this should not be a feature.
Clearly I shouldn't post code examples without lots and lots of explanatory comments. https://www.python.org/dev/peps/pep-0671/#implementation-details # REDEFINE THE INTERPRETER'S UNDERSTANDING # OF THE LATE BOUND DEFAULTS FOR THE FUNCTION f.__defaults_extra__ = ("n/a",) There, now it's a bit clearer what's going on. ChrisA