
On Sun, Dec 5, 2021 at 3:28 AM Chris Angelico <rosuav@gmail.com> wrote:
(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.)
Heck, or even " my signature is that other function's signature" -- that is what passing *args, **kwargs does, but you have to look at the implementation to know. As it happens, right now, someone on my team is trying out an implementation that uses inspect to grab the signature of superclass methods so that we can have a complete function signature without repeating ourselves all over the place. Not sure that's a good idea, but it would be cool if there were a standard and reliable way to do that. But yes, topic for another day.
None is most assuredly not going to trigger a late-bound default.
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.
But I'd like to see as a (perhaps rejected) idea is to have a new sentinel that does mean undefined.Sure there could be (rare) cases where you would need to have it a valid value, but then maybe you can't use late-bound defaults in that case. This is very different from None, because it would be new, so no one is already using it for anything else. And sure, folks could choose to use it inappropriately, but consenting adults and all 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 :)
Sure, that's ugly, but isn't the real problem here that foo(foo.any_unknown_attr) doesn't raise an Exception? Would we have that same issue in Python? e.g., doesn't Javascript already have: foo(); foo(foo.any_unknown_attr); lead to the same thing? whereas in Python, that would raise, yes? Or is there something special about undefined that I'm missing? (sorry, I don't really "get" Javascript) I personally think more standard special purpose sentinels would be a good idea, though I understand the arguments made against that in previous discussions. But this is a little different, because late-bound defaults are a new thing, so we don't already have a body of code using None, or anything else for "use the late bound default". -CHB -- Christopher Barker, PhD (Chris) Python Language Consulting - Teaching - Scientific Software Development - Desktop GUI and Web Development - wxPython, numpy, scipy, Cython