On Fri, May 14, 2021 at 7:31 PM Petr Viktorin email@example.com wrote:
Perhaps it would be beneficial to provide a common base class or factory, so we get a good repr. But I don't think another common value like None and Ellipsis would do much good.
Agreed - I think Sentinel would make a great class, from which you instantiate purpose-specific sentinels.
But maybe there really needs to be a way to NOT specify an argument, and to find out that an argument wasn't specified? Defaulting is only one way to handle it. Consider:
def truly_optional_arg(x, y, *z): """Two mandatory args, and then an optional one""" if z: print("Got an extra arg")
pass_arg = input("Pass the arg? ") == "y" truly_optional_arg(10, 20, *( if pass_arg else ))
It's horrifically ugly, but it really and truly does/doesn't pass that argument, and it really and truly detects whether one was passed. To make that sort of thing actually viable, there'd need to be some sort of language support; maybe something where the local name would start out unbound, but testing for a local's boundness is a clunky try/except, so that might also need some support.
Do we ever really need the ability to pass a specific sentinel to a function, or are we actually looking for a way to say "and don't pass this argument"?