Skip to content

Refactor PEP 661 sentinel handling to use a synthetic nominal class - #21894

Draft
edgarrmondragon wants to merge 1 commit into
python:masterfrom
edgarrmondragon:sentinel-nominal-types
Draft

Refactor PEP 661 sentinel handling to use a synthetic nominal class#21894
edgarrmondragon wants to merge 1 commit into
python:masterfrom
edgarrmondragon:sentinel-nominal-types

Conversation

@edgarrmondragon

@edgarrmondragon edgarrmondragon commented Aug 25, 2026

Copy link
Copy Markdown
Contributor

@edgarrmondragon
edgarrmondragon force-pushed the sentinel-nominal-types branch from d1c7eeb to 574e043 比较 August 25, 2026 17:21
@github-actions

This comment has been minimized.

@edgarrmondragon
edgarrmondragon force-pushed the sentinel-nominal-types branch from 574e043 to 0255ef7 比较 August 25, 2026 17:46
Signed-off-by: Edgar Ramírez Mondragón <edgarrm358@gmail.com>
@edgarrmondragon
edgarrmondragon force-pushed the sentinel-nominal-types branch from 0255ef7 to 785ebdc 比较 August 25, 2026 18:03
@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. ✅

@ilevkivskyi

Copy link
Copy Markdown
Member

I guess you want to cc @JelleZijlstra here.

@JelleZijlstra

Copy link
Copy Markdown
Member

If this fits better in mypy's model, I'm OK with landing it, but it feels worse to me. A sentinel isn't its own type, it's a single object that is an instance of the type sentinel. Treating it more like a literal makes more sense than treating it like a 新建Type.

@A5rocks

A5rocks commented Aug 28, 2026

Copy link
Copy Markdown
Collaborator

Maybe we can do the best of both worlds (less fragile, but fits @JelleZijlstra's mental model) by adding a test in copy_modified that if last_known_value is being removed, the type isn't a sentinel? IDK if there's a way to compile a check only into testing mypys instead of released mypys though!

@edgarrmondragon

Copy link
Copy Markdown
Contributor Author

adding a test in copy_modified that if last_known_value is being removed, the type isn't a sentinel?

I'd be happy with that compromise, but yeah I don't know if that's feasible.

注册 for free to join this conversation on GitHub. Already have an account? 登录 to comment

标签

None yet

项目

None yet

Development

Successfully merging this pull request may close these issues.

Invalid return type with sentinel and dict.get

5 participants