
On Wed, Oct 27, 2021 at 5:05 AM Paul Moore <p.f.moore@gmail.com> wrote:
On Tue, 26 Oct 2021 at 16:48, Eric V. Smith <eric@trueblade.com> wrote:
And also the "No Loss of Abilities If Removed" section sort of applies to late-bound function arguments: there's nothing proposed that can't currently be done in existing Python. I'll grant you that they might (might!) be more newbie-friendly, but I think the bar is high for proposals that make existing things doable in a different way, as opposed to proposals that add new expressiveness to the language.
One issue with not having an introspection capability, which has been bothering me but I've not yet had the time to come up with a complete example, is the fact that with this new feature, you have functions where there's no way to express "just use the default" without knowing what the default actually *is*.
Take for example
def f(a, b=None): if b is None: b = len(a) ...
def g(a, b=>len(a)): ...
Suppose you want to call f as follows:
args = [ ([1,2,3], 2), ([4,5,6], None), ([7,8,9], 4), ]
for a, b in args: f(a, b)
That works fine. But you cannot replace f by g, because None doesn't mean "use the default", and in fact by design there's *nothing* that means "use the default" other than "know what the default is and supply it explicitly". So if you want to do something similar with g (allowing the use of None in the list of tuples to mean "use the default"), you need to be able to introspect g to know what the default is. You may also need to manipulate first-class "deferred expression" objects as well, just to have something you can return as the default value (you could return a string and require the user to eval it, I guess, but that doesn't seem particularly user-friendly...)
I don't have a good solution for this, unfortunately. And maybe it's something where a "good enough" solution would be sufficient. But definitely, it should be discussed in the PEP so what's being proposed is clear.
Wouldn't cases like this be most likely to use *args and/or **kwargs? Simply omitting the argument from those would mean "use the default". Or am I misunderstanding your example here? ChrisA