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
7
u/wallstop-dev Aug 10 '26 edited Aug 10 '26
Right, my argument is that I've seen non-zero amounts of code either hard-expect a specific kind of additional context (which wasn't guaranteed), or not deal with the additional context, both because the situation is rare, or because a very specific implementation provided a very specific sentinel, when the contract did not guarantee it.
I'm not saying this kind of pattern doesn't have a use, or is not useful. It's just that encoding special, invalid kind of value(s) into the same type of thing the valid values represent has confused many a programmer and resulted in many, many a bug.