Skip to content

use LiteralString for sentinel name - #16094

Draft
DetachHead wants to merge 2 commits into
python:mainfrom
DetachHead:patch-5
Draft

use LiteralString for sentinel name#16094
DetachHead wants to merge 2 commits into
python:mainfrom
DetachHead:patch-5

Conversation

@DetachHead

@DetachHead DetachHead commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

type checkers enforce that the first argument to a sentinel is a string literal matching its name, which is enforced by the PEP: see https://peps.python.org/pep-0661/#typing

currently the type checkers contain logic to enforce that the argument is a string literal, but some of this special-casing can be removed if we use LiteralString in the stubs

some discussion in facebook/pyrefly#4142

equivalent PR in typing_extensions: python/typing_extensions#783

type checkers enforce that the first argument to a sentinel is a string literal matching its name, which is enforced by the PEP: see https://peps.python.org/pep-0661/#typing

currently the type checkers contain logic to enforce that the argument is a string literal, but some of this special-casing can be removed if we use `LiteralString` in the stubs
DetachHead added a commit to DetachHead/typing_extensions that referenced this pull request Jul 27, 2026
@github-actions

This comment has been minimized.

@AlexWaygood

Copy link
Copy Markdown
Member

type checkers enforce that the first argument to a sentinel is a string literal matching its name, which is enforced by the PEP: see https://peps.python.org/pep-0661/#typing

python/typing#2277 proposes to remove this text when adding this PEP to the spec and conformance suite. I think it would follow from that that it doesn't need to be a LiteralString either?

@DetachHead
DetachHead marked this pull request as draft July 27, 2026 06:50
@DetachHead

Copy link
Copy Markdown
Contributor Author

will keep this as a draft for now then until a decision is made

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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.

2 participants