PEP 661 introduces a new built-in `sentinel()` function coming in Python 3.15 that standardizes the creation of sentinel values. Sentinel values are placeholders used to distinguish between a missing value and an explicit `None`. The new built-in addresses drawbacks of current idioms: uninformative memory-address representations, lack of distinct types for type signatures, and unexpected behavior after copying or pickling. The `sentinel()` constructor takes a single string argument as the name, returns a unique object that is truthy, supports identity checks with `is`, and behaves correctly across copy and pickle operations. Each call creates a new sentinel, so it should be assigned to a variable for reuse.

10m watch time

Sort: