+1 for me on the usefulness of having a way to express "Missing Data".
One common use-case I encounter is in function signatures when one wants
arguments that are meant as overrides:
class Foo:
def __init__(self, bar=42, baz=None):
self.bar = bar
self.baz = baz
def do_something(bar_override=None, baz_override=None)
...
It works if None is not a valid value for bar or baz, but if it is, you'd have
to do something like this
class Missing:
pass
MISSING = object()
class Foo:
...
def do_something(bar_override=MISSING, baz_override=MISSING)
...
Which quickly becomes a problematic to type-hint: Union[Optional[int], Missing]
would be the correct way (mypy seems to agree), but is technically wrong.
Missing is a sentinel value, not a valid value for this argument. If MISSING
were an instance of a subclass of None, then Optional[int] should (in theory)
work and users of my method would be None the wiser (pun firmly intended :p).
PS: BTW, Missing/MISSING is how the dataclasses module does it
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/T2VT6ERGE5YPYXEGUSV5S5DFNE7PBUKR/
Code of Conduct: http://python.org/psf/codeofconduct/