TIL #144 – Sentinel built-in 0 ▲ mathspp.com feed 218 days ago · Tech · hide · Fediverse post Today I learned Python 3.15 will get a new sentinel built-in. Sentinel values are unique placeholder values that are commonly used in programming. Python 3.15 ships with a new built-in sentinel that can be used to create new sentinel values: # Python 3.15+ >>> MISSING = sentinel("MISSING") >>> MISSING MISSING Before this PEP, the most common sentinel idiom used the built-in object: MISSING = object() def my_function(some_arg=MISSING): if some_arg is MISSING: ... # Handle the sentinel In the function above, the sentinel value MISSING is being used to check whether the user passed anything as the parameter some_arg or not. PEP 661, that introduced this built-in, has a great discussion covering the reasons as to why this pattern, and many other sentinel patterns, fall short. In general, each common sentinel idiom suffers from at least one of the following problems: Bad string repr: the string representation is too long and uninformative Type unsafe: the sentinels don't have a distinct… Commenting on Bubbles has been removed. Why? If you want to talk about this post, write to the author, use the comments on their blog if it has them, or reply with a "RE:" post on your own blog. Suggestions? feedback@bubbles.town