Status of PEP 645? (Allow writing optional types as x?)
The typing-related PEP 645 - which introduces the syntax `T?` to mean `Optional[T]` - only has a single substantial related commit in the PEPs repo - the commit introducing the PEP (in Nov 2020) - and no discussions thread that I can find (on typing-sig or elsewhere). I'm personally quite interested in the potential capability to quickly signify `Optional[T]` since it is something I do a lot. What is the status of this PEP? Deferred for now? Withdrawn in favor of `T|None` syntax?† Something else? -- David Foster | Seattle, WA, USA Contributor to TypedDict, mypy, and Python's typing system † Through the grapevine I've been inferring that folks have been gravitating toward the slightly-shorter `T|None` syntax to spell `Optional[T]` in the meantime, and I even mention that spelling in my own PEP 655 (Required[]) [1] [1]: https://peps.python.org/pep-0655/#how-to-teach-this
I no longer support this. T|None is a fine way to write optional types, and doesn't require new syntax. We should also consider that in e.g. TypeScript, x? means something quite different than T|None; there, x? refers to allowing the absence of a parameter or field, not its type (more like NotRequired in your PEP 655). This could be confusing for users who use both languages. On Tue, Mar 29, 2022 at 10:26 PM David Foster <davidfstr@gmail.com> wrote:
The typing-related PEP 645 - which introduces the syntax `T?` to mean `Optional[T]` - only has a single substantial related commit in the PEPs repo - the commit introducing the PEP (in Nov 2020) - and no discussions thread that I can find (on typing-sig or elsewhere).
I'm personally quite interested in the potential capability to quickly signify `Optional[T]` since it is something I do a lot.
What is the status of this PEP? Deferred for now? Withdrawn in favor of `T|None` syntax?† Something else?
-- David Foster | Seattle, WA, USA Contributor to TypedDict, mypy, and Python's typing system
† Through the grapevine I've been inferring that folks have been gravitating toward the slightly-shorter `T|None` syntax to spell `Optional[T]` in the meantime, and I even mention that spelling in my own PEP 655 (Required[]) [1]
-- --Guido van Rossum (python.org/~guido) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
I can't report on the state of the PEP. I just would like to present another argument to not do this: `Optional`, in the first place, is a somewhat confusing misnomer: "`Optional` arguments of a function" are something different than "optional arguments of a function". In dictionary fields, an `Optional?` field is not "optional" either (just the value may be `None`). I think it is much more declarative to write `T | None` instead of `Optional[T]`. I think, the `T?` syntax would just be another way to stick to the idea of avoiding to write the more clear `T | None`. Am 30.03.2022 07:25 schrieb David Foster:
The typing-related PEP 645 - which introduces the syntax `T?` to mean `Optional[T]` - only has a single substantial related commit in the PEPs repo - the commit introducing the PEP (in Nov 2020) - and no discussions thread that I can find (on typing-sig or elsewhere).
I'm personally quite interested in the potential capability to quickly signify `Optional[T]` since it is something I do a lot.
What is the status of this PEP? Deferred for now? Withdrawn in favor of `T|None` syntax?† Something else?
The original author (Maggie Moss) isn't working on this anymore. Pyre is no longer in favor of adding new syntax for this because of concerns that Guido mentioned (`int | None` already exists, etc.). David: If you or others feel strongly about this, however, feel free to commandeer the PEP.
It sounds then like this PEP is Withdrawn: * Introducing new syntax/grammar has a high barrier to overcome, and the benefits of adding `x?` do not meet that bar (in the opinion of the Author & Sponsor) when `x|None` is short enough to write and more clear * Using `x?` to mean `x|None` is inconsistent with TypeScript where there it roughly means `NotRequired[x]`. Such inconsistency would likely confuse folks coming from TypeScript, a very popular language. Perhaps it would be useful to mark the PEP as Withdrawn, and provide a short paragraph at the top of the PEP summarizing why? Since I pretty much just wrote that paragraph with the bulleted list above 🙃, I'd be happy to make the edits myself if there are no objections. -- David Foster | Seattle, WA, USA Contributor to TypedDict, mypy, and Python's typing system On 3/30/22 1:53 PM, Pradeep Kumar Srinivasan wrote:
The original author (Maggie Moss) isn't working on this anymore. Pyre is no longer in favor of adding new syntax for this because of concerns that Guido mentioned (`int | None` already exists, etc.).
David: If you or others feel strongly about this, however, feel free to commandeer the PEP. _______________________________________________ Typing-sig mailing list -- typing-sig@python.org To unsubscribe send an email to typing-sig-leave@python.org https://mail.python.org/mailman3/lists/typing-sig.python.org/ Member address: davidfstr@gmail.com
I did draft a PR to withdraw PEP 645: https://github.com/python/peps/pull/2529 Best, -- David Foster | Seattle, WA, USA Contributor to TypedDict, mypy, and Python's typing system
participants (4)
-
David Foster
-
Guido van Rossum
-
j.scholbach@posteo.de
-
Pradeep Kumar Srinivasan