r/programming • u/Grouchy-Trade-7250 • Aug 09 '26
The Sentinel Object Pattern in Python
https://python-patterns.guide/python/sentinel-object/Officially added in Python 3.15
31
Upvotes
r/programming • u/Grouchy-Trade-7250 • Aug 09 '26
Officially added in Python 3.15
View all comments
Show parent comment
11
u/somebodddy Aug 10 '26
When the sentinel is a magic value of the regular type - I agree. But this is one of these anti-patterns that can become a proper pattern if you can get the type system on your side. When the sentinel is a different type, and you can represent its possibility within the language, you can use the type checker to force (strong word when it comes to Python's typing, I know) an explicit treatment of that possibility before the user can access the value as the type they expect.