Skip to content

Allow sentinels declared with bare Final/ClassVar in type expressions - #5574

Open
1-DARK wants to merge 1 commit into
meta:mainfrom
1-DARK:fix-sentinel-qualifier
Open

1-DARK wants to merge 1 commit into
meta:mainfrom
1-DARK:fix-sentinel-qualifier

Conversation

@1-DARK

@1-DARK 1-DARK commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

Summary

MARKER: Final = sentinel("MARKER") and MARKER: ClassVar = sentinel("MARKER") bound MARKER as a plain value, so int | MARKER reported not-a-type. The unannotated form already worked.

Annotated assignments never reached assign_sentinel. They went through the ordinary assignment path. A bare Final or ClassVar carries no type, so such sentinels are now bound like unannotated ones. Annotations that carry a type (A: A = Sentinel("A"), A: Any = ...) keep their current behavior, which existing tests rely on.

ClassVar is not a special export, so it is matched by name (ClassVar or x.ClassVar). An aliased import such as ClassVar as CV is not detected.

Fixes #5560

  • I am a human, and I fully understand the code I am submitting.

Test Plan

Added test_sentinel_with_type_qualifier in pyrefly/lib/test/sentinel.rs, covering the ClassVar and Final cases from the issue. cargo test sentinel passes.

@meta-cla meta-cla Bot added the cla signed label Nov 7, 2026
@github-actions github-actions Bot added the size/l label Nov 7, 2026
@github-actions

github-actions Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

✅ This PR meets all requirements from our pull request checklist.

Note: this comment updates automatically after changes to the PR. Updates may take up to half an hour.

…sions

A sentinel assigned with an annotation went through the ordinary assignment
path and became a value, so `MARKER: Final = sentinel("MARKER")` could not
be used as a type. Bind such sentinels like unannotated ones when the
annotation is a bare Final or ClassVar.
@1-DARK
1-DARK force-pushed the fix-sentinel-qualifier branch from 79b59cc to c3cd030 Compare November 7, 2026 16:28
@github-actions github-actions Bot added size/xs and removed size/l labels Nov 7, 2026
@meta-codesync

meta-codesync Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

This pull request has been imported. If you are a Meta employee, you can view this in D130435706. (Because this pull request was imported automatically, there will not be any future comments.)

@github-actions

github-actions Bot commented Nov 7, 2026

Copy link
Copy Markdown

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

This branch has not been deployed

No deployments
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.

py3.15: error with sentinel + type qualifier (Final / ClassVar)

2 participants