PEP 661 (Sentinel Values) has been accepted for release in 3.15!

Posted by M_V_Lipwig@reddit | Python | View on Reddit | 88 comments

After five years of discussion, PEP 661, which adds support for sentinel values, has been accepted and is due for a release in 3.15. The motivation is relatively simple:

MISSING = sentinel('MISSING')

def read_value(default= str | MISSING):
  if default is MISSING:
    default = "foo" 
  elif default is None:
    default = "bar"
  else:
    ...

The important thing here is a specific way to check if any argument was provided to the function, vs a caller propagating a None to it. The ability to check if an argument was actually provided by the caller was a great feature I liked in FORTRAN, so it's nice that it's made it to python!