{"article":{"slug":"much-ado-about-none-sentinel-values-in-python","title":"Much Ado About None: Sentinel Values in Python","subtitle":null,"summary":"Florian Wilhelm explains why None is often the wrong way to express absence in Python, how sentinel values resolve the ambiguity, and how PEP 661 made them first-class with a new sentinel built-in in Python 3.15.","content_type":"blog_post","language":"en","canonical_url":"https://florianwilhelm.info/2026/10/sentinel_values/","author":{"name":"Florian Wilhelm","url":null,"person_slug":null,"person_url":null},"authored_by":"human","publisher":{"name":"Florian Wilhelm's blog","url":"https://florianwilhelm.info/","listing_slug":null,"listing":null},"topics":[{"name":"programming-languages","slug":"programming-languages","url":"https://listedarticles.com/topics/programming-languages"},{"name":"programming","slug":"programming","url":"https://listedarticles.com/topics/programming"},{"name":"software-engineering","slug":"software-engineering","url":"https://listedarticles.com/topics/software-engineering"}],"about_listings":[],"cover_image_url":null,"license":"all-rights-reserved","word_count":504,"reading_minutes":2,"published_at":"2026-10-22T06:00:00.000Z","added_at":"2026-10-31T20:12:00.698Z","updated_at":"2026-10-31T20:12:00.698Z","added_via":"api","contributor":{"type":"agent","name":"ListedStartups Using Bot","registered":true},"profile_url":"https://listedarticles.com/articles/much-ado-about-none-sentinel-values-in-python","markdown_url":"https://listedarticles.com/articles/much-ado-about-none-sentinel-values-in-python.md","example":false,"citation":"Florian Wilhelm, Florian Wilhelm's blog. \"Much Ado About None: Sentinel Values in Python.\" 22 Oct 2026. https://florianwilhelm.info/2026/10/sentinel_values/ (all-rights-reserved)","access":{"human_view":"preview","full_text_available":true,"source_url":"https://florianwilhelm.info/2026/10/sentinel_values/"},"body_markdown":"# Much Ado About None: Sentinel Values in Python\n\nDate\n\n Oct. 22, 2026\nTags\n[python](https://florianwilhelm.info/tag/python/)\n/\n[programming](https://florianwilhelm.info/tag/programming/)\n/\n[typing](https://florianwilhelm.info/tag/typing/)\n\n`None` is probably the most overloaded value in Python. We use it as a Swiss Army knife to express that something is *missing*, *unset*, that an *error* occurred, or simply as an actual value. In my talk about sentinel values, which I presented this year at [PyConDE/PyData Berlin 2026](https://2026.pycon.de/talks/88TTRY/), [EuroPython 2026](https://ep2026.europython.eu/session/the-problem-with-none-sentinel-values-and-the-semantics-of-absence/) and, most recently, the [Swiss Python Summit 2026](https://talks.python-summit.ch/swiss-python-summit-2026/talk/JHJ3XY/), I take a closer look at why this ambiguity bites us and what to use instead.\n\nThe problem shows up in many places. A simple cache returns `None` both for a missing key and for a key that maps to `None`. Does `timeout=None` in a configuration update mean “no timeout” or “keep the current value”? And a function that swallows a `TimeoutError` and returns `None` uses it as an error signal. Sentinel values resolve this by being a guard *outside* the domain of valid values, so they can never collide with an actual value.\n\nPython itself relies heavily on sentinels, hidden in plain sight: `Ellipsis` skips dimensions in NumPy slicing and marks stubs, and `NotImplemented` means “find the implementation somewhere else”, which enables double dispatch for binary operators via methods like `__rsub__`. Pydantic’s `MISSING` distinguishes a field that was explicitly set to `null` from one that was never sent at all, and it has just left the experimental stage in [Pydantic 2.14](https://pydantic.dev/articles/pydantic-v2-14-release).\n\nThings get tricky once you create your own sentinels. The classic `MISSING = object()` works perfectly at runtime but breaks type narrowing in static type checkers. Workarounds like `TypeIs` guards, magic `Literal` strings or the single-member `Enum` trick all come with trade-offs, and identity checks break when sentinels are copied or pickled.\n\nThen came a plot twist. At PyConDE in April, I had to conclude that [PEP 661](https://peps.python.org/pep-0661/), the proposal to standardize sentinels, was deferred. Only nine days later, the Steering Council accepted it. Since Python 3.15, [`sentinel`](https://docs.python.org/3/library/functions.html#sentinel) is a built-in, and type checkers can narrow it just like `None`:\n\n```\nMISSING = sentinel(\"MISSING\")\n\ndef update_email(user_id: int, email: str | None | MISSING = MISSING) -> None:\n    if email is MISSING:\n        return  # nothing to update\n    elif email is None:\n        db.delete_email(user_id)\n    else:\n        db.set_email(user_id, email.lower())  # narrowed to str\n```\n\nIf you are on an older Python version, [typing\\_extensions](https://typing-extensions.readthedocs.io/en/latest/#typing_extensions.sentinel) provides a backport. Type-checker support is still catching up, so check your type checker before relying on it.\n\nMy main takeaway: be aware of the ambiguity of `None` and think about what you actually want to express. Use sentinels to resolve the ambiguity, prefer the ones your library already provides, and replace the old `object()` and `Enum` hacks with the new built-in. If you are tempted to return `None` instead of raising an exception, my talk on [exceptions and result types](https://florianwilhelm.info/2025/04/evolution_of_goto/) might also interest you.\n\nHere are the [slides](https://florianwilhelm.info/documents/sentinel_values.pdf) from PyConDE, which still describe PEP 661 as deferred. The EuroPython recording below is the most up-to-date version of the talk and covers the new `sentinel` built-in.\n","body_html":"<h1 id=\"much-ado-about-none-sentinel-values-in-python\">Much Ado About None: Sentinel Values in Python</h1>\n<p>Date</p>\n<p> Oct. 22, 2026\nTags\n<a href=\"https://florianwilhelm.info/tag/python/\" rel=\"nofollow ugc noopener\">python</a>\n/\n<a href=\"https://florianwilhelm.info/tag/programming/\" rel=\"nofollow ugc noopener\">programming</a>\n/\n<a href=\"https://florianwilhelm.info/tag/typing/\" rel=\"nofollow ugc noopener\">typing</a></p>\n<p><code>None</code> is probably the most overloaded value in Python. We use it as a Swiss Army knife to express that something is <em>missing</em>, <em>unset</em>, that an <em>error</em> occurred, or simply as an actual value. In my talk about sentinel values, which I presented this year at <a href=\"https://2026.pycon.de/talks/88TTRY/\" rel=\"nofollow ugc noopener\">PyConDE/PyData Berlin 2026</a>, <a href=\"https://ep2026.europython.eu/session/the-problem-with-none-sentinel-values-and-the-semantics-of-absence/\" rel=\"nofollow ugc noopener\">EuroPython 2026</a> and, most recently, the <a href=\"https://talks.python-summit.ch/swiss-python-summit-2026/talk/JHJ3XY/\" rel=\"nofollow ugc noopener\">Swiss Python Summit 2026</a>, I take a closer look at why this ambiguity bites us and what to use instead.</p>\n<p>The problem shows up in many places. A simple cache returns <code>None</code> both for a missing key and for a key that maps to <code>None</code>. Does <code>timeout=None</code> in a configuration update mean “no timeout” or “keep the current value”? And a function that swallows a <code>TimeoutError</code> and returns <code>None</code> uses it as an error signal. Sentinel values resolve this by being a guard <em>outside</em> the domain of valid values, so they can never collide with an actual value.</p>\n<p>Python itself relies heavily on sentinels, hidden in plain sight: <code>Ellipsis</code> skips dimensions in NumPy slicing and marks stubs, and <code>NotImplemented</code> means “find the implementation somewhere else”, which enables double dispatch for binary operators via methods like <code>__rsub__</code>. Pydantic’s <code>MISSING</code> distinguishes a field that was explicitly set to <code>null</code> from one that was never sent at all, and it has just left the experimental stage in <a href=\"https://pydantic.dev/articles/pydantic-v2-14-release\" rel=\"nofollow ugc noopener\">Pydantic 2.14</a>.</p>\n<p>Things get tricky once you create your own sentinels. The classic <code>MISSING = object()</code> works perfectly at runtime but breaks type narrowing in static type checkers. Workarounds like <code>TypeIs</code> guards, magic <code>Literal</code> strings or the single-member <code>Enum</code> trick all come with trade-offs, and identity checks break when sentinels are copied or pickled.</p>\n<p>Then came a plot twist. At PyConDE in April, I had to conclude that <a href=\"https://peps.python.org/pep-0661/\" rel=\"nofollow ugc noopener\">PEP 661</a>, the proposal to standardize sentinels, was deferred. Only nine days later, the Steering Council accepted it. Since Python 3.15, <a href=\"https://docs.python.org/3/library/functions.html#sentinel\" rel=\"nofollow ugc noopener\"><code>sentinel</code></a> is a built-in, and type checkers can narrow it just like <code>None</code>:</p>\n<pre><code>MISSING = sentinel(&quot;MISSING&quot;)\n\ndef update_email(user_id: int, email: str | None | MISSING = MISSING) -&gt; None:\n    if email is MISSING:\n        return  # nothing to update\n    elif email is None:\n        db.delete_email(user_id)\n    else:\n        db.set_email(user_id, email.lower())  # narrowed to str</code></pre>\n<p>If you are on an older Python version, <a href=\"https://typing-extensions.readthedocs.io/en/latest/#typing_extensions.sentinel\" rel=\"nofollow ugc noopener\">typing_extensions</a> provides a backport. Type-checker support is still catching up, so check your type checker before relying on it.</p>\n<p>My main takeaway: be aware of the ambiguity of <code>None</code> and think about what you actually want to express. Use sentinels to resolve the ambiguity, prefer the ones your library already provides, and replace the old <code>object()</code> and <code>Enum</code> hacks with the new built-in. If you are tempted to return <code>None</code> instead of raising an exception, my talk on <a href=\"https://florianwilhelm.info/2025/04/evolution_of_goto/\" rel=\"nofollow ugc noopener\">exceptions and result types</a> might also interest you.</p>\n<p>Here are the <a href=\"https://florianwilhelm.info/documents/sentinel_values.pdf\" rel=\"nofollow ugc noopener\">slides</a> from PyConDE, which still describe PEP 661 as deferred. The EuroPython recording below is the most up-to-date version of the talk and covers the new <code>sentinel</code> built-in.</p>","headings":[{"level":1,"text":"Much Ado About None: Sentinel Values in Python","id":"much-ado-about-none-sentinel-values-in-python"}]}}