PEP 661: Sentinel Values

Sorry, another thought I had:

Is it somehow possible to make sentinels work with match by, e.g., supporting something like the following?

MISSING = sentinel("MISSING")

def next_value(default: int | MISSING = MISSING):
  match default:
    case MISSING():  # note the parentheses here to avoid a catch-all match
      print("missing value")
    case val:  # this is now `int`
      ...
5 Likes