Skip to content

Add Sentinel support (PEP-661)#3575

Draft
hrolfurgylfa wants to merge 1 commit into
facebook:mainfrom
hrolfurgylfa:PEP-661-Sentinel
Draft

Add Sentinel support (PEP-661)#3575
hrolfurgylfa wants to merge 1 commit into
facebook:mainfrom
hrolfurgylfa:PEP-661-Sentinel

Conversation

@hrolfurgylfa
Copy link
Copy Markdown

Summary

This PR adds support for PEP 661 Sentinel types.

Fixes #3207

Test Plan

I've run this as an LSP for a bit on a bigger private repo and it seems to work, but the main testing was the tests added to test/narrow.rs and test/sentinel.rs.

Some assumptions/things I didn't fully understand and might deserve more attention:

  • I'm using NestingContext::toplevel() when creating a Sentinel struct, this is similar to TypeVar/TypeAlias/a few others, I left the same TODO in place as they had. I looked through some of the other types and couldn't find any other way it was being done, so I left it like this for now, but if anyone has any pointers to how it should be done better, please let me know and I can fix it.

  • For the cinderx support, I added the sentinel to it in the TODO section of variables that get set to Any. I haven't really diven into what cinderx is and how the support for it is implemented, but if it is important to get it working I can go ahead and look into that.

  • I'm using bind_legacy_type_var_or_typing_alias to bind the Sentinel type, I think this should be ok as the PEP is pretty strict in how it can be assigned. I've done some testing and only found one edge case so far that fails because of this, but I don't think Final's should be mixed with Sentinel objects like this anyway, here is the test case that fails:

from typing import Any, Final
from typing_extensions import Sentinel

MISSING: Final[Any]
MISSING = Sentinel("MISSING")

It fails because the Final doesn't notice the assignment, it still thinks the variable was never assigned to.

Status

This PR is mostly ready for review, but I'm keeping it in Draft form until #3562 is addressed, since until then I can't finalize Python 3.15 support.

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 25, 2026

Hi @hrolfurgylfa!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla
Copy link
Copy Markdown

meta-cla Bot commented May 25, 2026

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Sentinel types in pydantic models

1 participant