Beyond None: Mastering Sentinel Objects for Cleaner Python Code
Published:
If you’ve ever used None
to represent “missing” or “default” values in Python, you’ve likely run into a subtle problem: what if None
is a valid input for your function or data structure? For example, a caching function might need to distinguish between a cached None
value and the absence of a cached value altogether. Using None
for both cases creates ambiguity and bugs that are hard to trace.
Read more