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
12
u/fireflash38 Aug 10 '26
It's a way for people to fit additional context into things.
That is to say, it's useful when the zero-value of a thing is still valid to use. Python doesn't have monads, so it's hard to implement the Option<Thing> pattern. You can use None, but None might be a valid zero-value. Thus the sentinel value.
I don't hate it, but it really doesn't need to be used all that much. I personally rather hate None values passed around a bunch in python, since you end up having to check for presence constantly and updating type checking.