You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since this PEP proposes a change to the type system (an extension of the values allowed in Literal[]), the Typing Council is also looking at it. We'll discuss internally and share our opinion here if the Steering Council thinks it's helpful.
The PEP currently proposes to use Literal[SentinelName] as the type annotation to describe the type of a sentinel object. We prefer to support SentinelName directly without the need to wrap it in a Literal . This would require the sentinel base class to supply a __or__ method to support unions, which would be straightforward. The most common sentinel value used in Python is None, and it is special-cased in the type system to not require Literal[None] in a type annotation. Since type checkers (both static and runtime) will already need to special-case sentinels, we wouldn’t gain any simplicity by forcing users to wrap sentinels in Literal[].
A suggestion came up to allow both forms in type annotations, Literal[SentinelName] and SentinelName. We prefer to keep only the latter so we don’t introduce redundant ways to describe the same type.
(Note from me personally: The change we're recommending here aligns with something Tal already said he was planning to change in the PEP, leading to Petr's message above.)
Please consider PEP 661 -- Sentinel Values
https://peps.python.org/pep-0661/
Post-History
headerPost-History
)The text was updated successfully, but these errors were encountered: