steering-council icon indicating copy to clipboard operation
steering-council copied to clipboard

PEP 661 -- Sentinel Values

Open taleinat opened this issue 1 year ago • 4 comments

Please consider PEP 661 -- Sentinel Values https://peps.python.org/pep-0661/

  • [X] The PEP has been discussed in threads listed in its Post-History header
  • [X] The PEP was announced on Discuss (link in Post-History)
  • [X] The PEP includes all relevant Suggested Sections
  • [X] The PEP includes endorsements from the projects/groups/people it helps
  • [X] The PEP has a CODEOWNERS entry

taleinat avatar Oct 13 '24 20:10 taleinat

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.

JelleZijlstra avatar Oct 14 '24 16:10 JelleZijlstra

Note that there is some more discussion on Discourse, and the PEP might need to be changed.

encukou avatar Oct 15 '24 09:10 encukou

On behalf of the Typing Council:

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.)

JelleZijlstra avatar Oct 16 '24 17:10 JelleZijlstra

Thank you @JelleZijlstra and members of the Typing Council! Your opinions and feedback are greatly appreciated.

I now agree that SentinelName is preferable to Literal[SentinelName]. I greatly prefer only SentinelName rather than both options.

taleinat avatar Oct 18 '24 11:10 taleinat

Please note that the PEP has been amended to reflect the changes to typing as described by @JelleZijlstra above.

taleinat avatar Oct 25 '24 07:10 taleinat

FYI, the current SC decided to leave this PEP for the next SC to decide, given that SC elections are very soon (https://discuss.python.org/t/steering-council-nominations-will-open-november-7th-2024).

Yhg1s avatar Oct 25 '24 12:10 Yhg1s

I've created a PR with suggested post-submission changes to the PEP proposal. https://github.com/python/peps/pull/4232

I understand that the SC has recently begun reviewing this proposal. If possible, please consider the proposal to include these changes.

taleinat avatar Jan 26 '25 21:01 taleinat

Also, please note that the current proposal suggests adding a new stdlib module, "sentinellib". It has been suggested to add a new "sentinel" builtin, instead, or to add this to the "typing" module; I consider all of these to be valid options.

taleinat avatar Jan 26 '25 21:01 taleinat

SC review status: still on our radar, we're catching up on the latest in the Discuss thread before we can make any decisions.

gpshead avatar Feb 06 '25 22:02 gpshead

The SC is waiting for a response on our offer of office hours to @taleinat

Until then we are in a holding pattern for PEP 661.

warsaw avatar Mar 20 '25 17:03 warsaw

The SC has decided to defer PEP 661. I'm going to close this ticket, but please do consider reopening this for Python 3.15.

warsaw avatar Apr 10 '25 18:04 warsaw