On Sun, Dec 5, 2021 at 9:58 PM Barry Scott <ba...@barrys-emacs.org> wrote:
 >> def inner(timestamp=>time.time()):
> >    if timestamp is None: timestamp = time.time()
>
>
> And, obviously, if you end up needing the write the explicit check for None 
> there is no
> advantage to using late bound default.

Hmm, I wouldn't say NO advantage - it still puts the primary and
meaningful default in the signature, but then has a special case for
backward compatibility, or for that one caller where it makes sense,
or whatever. But yes, far less advantage when you actually have None
as part of your API. The main point of late-bound defaults is to
remove None from the API.

> Yes that's a good point. Use the *kwargs style to pass down stuff.

That's normally the recommendation anyway. It's safe against
additional parameters being added, it's safe against the defaults
changing, it clearly says "this passes on its arguments unchanged";
the only problem is that the help for the function doesn't adequately
show what parameters it can actually accept. And that's a fundamental
problem - look at these docs:

https://docs.python.org/3/library/subprocess.html#subprocess.run

"""The arguments shown above are merely the most common ones,
described below in Frequently Used Arguments (hence the use of
keyword-only notation in the abbreviated signature)."""

The docs aren't restricted to what can be implemented in an actual
function signature, yet it's still most effective to just toss in
"**other_popen_kwargs" at the end.

(That said, though: it would be rather nice to be able to do algebra
with function signatures. For instance, you could say "my signature is
that function's kwargs plus frobnosticate=42" or "my signature is that
function's kwargs minus stdin". But that's a topic for another thread
or another day.)

> > None is most assuredly not going to trigger a late-bound default.
>
> Are you state that this is because in most of the cases where I might think 
> that I need this behaviour there are better patterns to use like *kwargs?
> Is that worth stating in the PEP in the rejected ideas?

I don't think so, because None doesn't mean "omit this argument". It
is a perfectly valid value. There's also no need to say that object()
won't trigger late-bound defaults, or 0, or anything else. The only
way to cause a default argument to be evaluated is to not pass the
argument - as is already the case.

> > Python is not JavaScript :)
>
> Thank your choice of deity for that!

Yeah :) I say this because, in JavaScript, there is fundamentally no
difference between passing the special value 'undefined' (kinda like
None, although there's also null as a separate value) and not passing
the argument at all, which means that...

function foo(x="hello") {console.log("x is " + x);}
foo(undefined);
foo(foo.any_unknown_attr);

will print "x is hello" twice. I don't want that :) And that's why
there is, by definition, no value that will cause a function to think
that an argument wasn't passed.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/F2PGWFKFYX3BMKKOH5QJ2XIR4KLUX3M6/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to