Much Ado About None: Sentinel Values in Python

(florianwilhelm.info)

20 points | by sebg 1 day ago

4 comments

  • pwdisswordfishq 3 minutes ago
    So much trouble to avoid introducing the optional monad.
  • lpghatguy 34 minutes ago
    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.

  • RantyDave 49 minutes ago
    "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.

    • travisd 23 minutes ago
      it’s maybe less “pythonic” but at $dayjob we’ve very actively moved away from exceptions for things in favor of things that are statically type checked. too many things that become runtime bugs instead of type checking bugs.

      with match now being available, we even return explicit error objects and the ergonomics are pretty good (reminds me of rust).

    • lyorig 39 minutes ago
      Perhaps the author has had their fair share of run-ins with libraries that didn't think their API through like that. But yes, they should.
  • chowells 58 minutes ago
    I like it. I can't see how to do better while remaining compatible with Python idioms.