Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 661 -- Sentinel Values #258

Open
5 tasks done
taleinat opened this issue Oct 13, 2024 · 6 comments
Open
5 tasks done

PEP 661 -- Sentinel Values #258

taleinat opened this issue Oct 13, 2024 · 6 comments
Labels
PEP Python Enhancement Proposal

Comments

@taleinat
Copy link

taleinat commented Oct 13, 2024

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

  • The PEP has been discussed in threads listed in its Post-History header
  • The PEP was announced on Discuss (link in Post-History)
  • The PEP includes all relevant Suggested Sections
  • The PEP includes endorsements from the projects/groups/people it helps
  • The PEP has a CODEOWNERS entry
@taleinat taleinat added the PEP Python Enhancement Proposal label Oct 13, 2024
@JelleZijlstra
Copy link
Member

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.

@encukou
Copy link
Member

encukou commented Oct 15, 2024

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

@JelleZijlstra
Copy link
Member

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

@taleinat
Copy link
Author

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
Copy link
Author

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

@Yhg1s
Copy link
Member

Yhg1s commented Oct 25, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PEP Python Enhancement Proposal
Projects
None yet
Development

No branches or pull requests

4 participants