
On Sun, Oct 31, 2021 at 02:56:36PM +1100, Chris Angelico wrote:
Current versions of the PEP do not use the term "default value" when referring to late binding (or at least, if I've made a mistake there, then please point it out so I can fix it). I'm using the term "default expression", or just "default" (to cover both values and expressions).
I was just thinking of suggesting that to you, so I'm glad to see you're much faster on the uptake than I am! Of course all parameters are syntactically an expression, including now: # the status quo def func(arg=CONFIG.get('key', NULL)): The default expression is evaluated at function definition time, and the result of that (an object, a.k.a. a value) is cached in the function object for later use. With late-binding: def func(@arg=CONFIG.get('key', NULL)): the expression is stashed away somewhere (implementation details), in some form (source code? byte-code? an AST?) rather than immediately evaluated. At function call time, the expression is evaluated, and the result (an object, a.k.a. a value) is bound to the parameter. In neither case is it correct to say that the default value of arg is the *expression* `CONFIG.get('key', NULL)`, it is in both the early and late bound cases the *result* of *using* (evaluating) the expression to generate a value. https://en.wikipedia.org/wiki/Use%E2%80%93mention_distinction I'm fairly confident that everyone understands that: "the default value is CONFIG.get('key', NULL)" is shorthand for the tediously long and pedantic explanation that it's not the expression itself that is the default value, but the result of evaluating the expression. Just like we understand it here: if arg is None: arg = CONFIG.get('key', NULL) The only difference is when the expression is evaluated. If we can understand that arg gets set to the result of the expression in the second case (the None sentinel), we should be able to understand it in if the syntax changes to late-bound parameters. -- Steve