Skip to content

Recognize typing_extensions.sentinel as a sentinel constructor#4254

Open
MannXo wants to merge 1 commit into
facebook:mainfrom
MannXo:fix/issue-4225-lowercase-sentinel-typing-extensions
Open

Recognize typing_extensions.sentinel as a sentinel constructor#4254
MannXo wants to merge 1 commit into
facebook:mainfrom
MannXo:fix/issue-4225-lowercase-sentinel-typing-extensions

Conversation

@MannXo

@MannXo MannXo commented Jul 22, 2026

Copy link
Copy Markdown

Summary

typing_extensions 4.16.0 backported the lowercase PEP 661 sentinel (the form Python 3.15 exposes as builtins.sentinel), but Pyrefly only treated the lowercase name as a sentinel constructor when it came from builtins: the BuiltinsSentinel special export's defined_in gate listed only that module. So from typing_extensions import sentinel; X = sentinel("X") fell through to a plain function call, and reveal_type(X) showed sentinel instead of the unique sentinel type, diverging from the uppercase Sentinel it replaces. (As you noted on the issue, this just needed adding to the module gate.)

The fix widens BuiltinsSentinel's defined_in to also allow typing_extensions. Sentinel and BuiltinsSentinel already route to the same sentinel-construction path in binding/stmt.rs, so the module gate was the only thing wrong.

Fixes #4225

Test Plan

Added two cases to pyrefly/lib/test/sentinel.rs:

  • test_sentinel_lowercase_from_typing_extensionsfrom typing_extensions import sentinel now narrows/assert_types like the uppercase Sentinel.
  • test_sentinel_lowercase_from_typing_extensions_reveal — the issue's repro: reveal_type reports the sentinel type, not sentinel.

cargo test -p pyrefly sentinel → 33 passed, 0 failed. Confirmed both new tests fail without the one-line fix (2 failed, "expected 0 errors, but got 3"). cargo clippy -p pyrefly and cargo fmt --check are clean.

Note: built and tested against the 1.95.0 stable toolchain (this environment couldn't download the pinned stable). I did not run test.py's conformance regeneration — the change only widens a module gate for typing_extensions.sentinel and touches no behavior the python/typing conformance suite covers, so I don't expect generated changes, but flagging in case CI disagrees.

Disclosure: this PR was prepared with the help of Claude Opus 4.8, an AI coding agent, under my direction and review.

typing_extensions 4.16.0 backported the lowercase PEP 661 `sentinel` (the
form Python 3.15 exposes as `builtins.sentinel`), but Pyrefly only treated
the lowercase name as a sentinel constructor when it came from `builtins`:
the `BuiltinsSentinel` special export was gated to that module alone.
Imported from `typing_extensions`, it fell through to a plain function
call, so `x = sentinel("x")` was typed as the function's return type
instead of a unique sentinel, diverging from the uppercase `Sentinel` it
is meant to replace.

Widen `BuiltinsSentinel`'s module gate to also accept `typing_extensions`.
Both names already route to the same sentinel-construction path, so the
gate was the only thing wrong.

Fixes facebook#4225
@meta-cla

meta-cla Bot commented Jul 22, 2026

Copy link
Copy Markdown

Hi @MannXo!

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

meta-cla Bot commented Jul 22, 2026

Copy link
Copy Markdown

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

@meta-cla meta-cla Bot added the cla signed label Jul 22, 2026
@meta-cla

meta-cla Bot commented Jul 22, 2026

Copy link
Copy Markdown

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

@github-actions

Copy link
Copy Markdown

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

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.

lowercase typing_extensions.sentinel not handled right

2 participants