Skip to content

Add support for PEP 661 (sentinels)#21454

Open
JelleZijlstra wants to merge 4 commits intopython:masterfrom
JelleZijlstra:sentinels
Open

Add support for PEP 661 (sentinels)#21454
JelleZijlstra wants to merge 4 commits intopython:masterfrom
JelleZijlstra:sentinels

Conversation

@JelleZijlstra
Copy link
Copy Markdown
Member

See PEP 661 and python/typing#2277

@github-actions

This comment has been minimized.

Copy link
Copy Markdown
Member

@sobolevn sobolevn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff! 👍

Comment thread test-data/unit/check-sentinels.test
@github-actions
Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@cdce8p
Copy link
Copy Markdown
Collaborator

cdce8p commented May 11, 2026

Thanks for working on it! I took some time to start testing it for Home Assistant.

I did encounter an issue during the cache restore

Traceback (most recent call last):
  File "/.../python3.14/site-packages/mypy/__main__.py", line 16, in console_entry
    main()
    ~~~~^^
  File "mypy/main.py", line 154, in main
  File "mypy/main.py", line 244, in run_build
    res = build.build(sources, options, None, flush_errors, fscache, stdout, stderr)
  File "mypy/build.py", line 422, in build
  File "mypy/build.py", line 537, in build_inner
    graph = dispatch(sources, manager, stdout, connect_threads)
  File "mypy/build.py", line 4150, in dispatch
    process_graph(graph, manager)
  File "mypy/build.py", line 4618, in process_graph
    done, still_working, results = manager.wait_for_done(graph)
  File "mypy/build.py", line 1492, in wait_for_done
    process_stale_scc(graph, next_scc, self)
  File "mypy/build.py", line 4765, in process_stale_scc
    maybe_load_deps(graph, ascc, manager)
  File "mypy/build.py", line 4749, in maybe_load_deps
    process_fresh_modules(graph, sorted(prev_scc.mod_ids), manager)
  File "mypy/build.py", line 4700, in process_fresh_modules
    graph[id].load_tree()
  File "mypy/build.py", line 3120, in load_tree
    self.tree = MypyFile.read(data_io)
  File "mypy/nodes.py", line 609, in read
  File "mypy/nodes.py", line 5131, in read
    [(read_str_bare(data), SymbolTableNode.read(data)) for _ in range(size)]
  File "mypy/nodes.py", line 5046, in read
    sym._node_bytes = extract_symbol(data)
ValueError: Unsupported tag: 8

Looks like LITERAL_SENTINEL needs to be added to librt_internal.c as well from what I can tell.

--
Besides that I did see a couple of Cannot assign to final name messages which were unexpected. I've defined most sentinels in the style _SENTINEL = Sentinel("_SENTINEL"). I'd have expected that as long as the sentinel isn't imported, I can reuse the value / variable name just fine in a different module. Am I missing something?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants