logoalt Hacker News

Much Ado About None: Sentinel Values in Python

27 points • by sebg • last Thursday at 10:24 PM • 13 comments • view on HN

Comments

pwdisswordfishq • today at 9:01 PM

So much trouble to avoid introducing the optional monad.

➕ show 2 replies
lpghatguy • today at 8:31 PM

When I was writing a bunch of Lua, I was a big fan of having a None sentinel value (Lua uses 'nil' for representing absence) and it was useful for a lot of things similar to Pydantic's MISSING.

This distinction is something that I think is actually handy about JavaScript, and distinguishing between 'null' and 'undefined' is sometimes useful for similar reasons.

chowells • today at 8:07 PM

I like it. I can't see how to do better while remaining compatible with Python idioms.

➕ show 1 reply
RantyDave • today at 8:16 PM

"A simple cache returns None both for a missing key and for a key that maps to None."

No, it returns KeyError. Or at least it should.

➕ show 3 replies