![](https://secure.gravatar.com/avatar/5615a372d9866f203a22b2c437527bbb.jpg?s=120&d=mm&r=g)
On Mon, Nov 01, 2021 at 09:39:01AM +0100, Evpok Padding wrote:
I don't look forward to having to add yet another side note about syntactic sugar that does not really add much value (it saves a few characters but it's less clear
This proposal is not about saving a few characters. We could keep the PEP and change the syntax to use a long keyword: def func(arg=late_binding_through_delayed_evaluation expression) (where "expression" is an actual expression) and it would still have the same benefits. Just more awkward to type :-)
and relying on code to document the parameters is a bit meh imo).
Do you think it is a problem that help() can introspect function signatures and report what the actual defaults are, rather than whatever lies are put in the docstring? I think that is a fantastic feature for Python, but it only applies to early defaults. def func(arg=''): """Return a thing. Arguments: arg is a string, defaults to space. """ When possible, the single source of truth for a function's defaults should be the actual parameter defaults, regardless of when the default is evaluated.
Because I won't burden beginners who are already having to ingest a lot of thing with a new model of evaluation.
We're not proposing this feature for the benefit of newbies and beginners. Python is remarkably beginner friendly, but it's not Scratch. The first edition of Learning Python (Mark Lutz and David Ascher) didn't introduce function defaults until page 122, right at the end of Chapter Four. And of course they had to mention the mutable object gotcha. We do people a disservice if we don't introduce at least the concept of when the default is evaluated. If we don't, they will invariably trip into the "mutable default" gotcha on their own and confuse themselves. I don't think the distinction between early and late binding is a hard concept to teach. What does this do? def func(arg=print("Hello")): return arg func() func() That's all you need to show to demonstrate early binding. Now this: def func(arg=late print("Hello")): return arg func() func() Having *both* options available, and teaching it as a choice, will (I think) make it easier to teach, not harder. "Write `arg=default` if you want the default to be evaluated just once, and `arg=late default` if you want the default to be evaluated each time it is needed. If you are not sure which one you need, use the first." That's the sort of advice I would have loved when I was a newbie. Short, simple, straight to the point, and not reliant on knowing what "is None" means. -- Steve