Closed
Description
Multiple people have suggested a shorter syntax to replace Optional[...]
. The current syntax will become more inconvenient if we don't infer optional types from None
default values (see #275).
Here are various options that I remember seeing proposed:
x?
or?x
This would require new Python syntax.
Hack uses ?x
. TypeScript uses x?
for names, not types, if I've understood things correctly.
x | None
This would require support for |
for all type objects, which would not be backward compatible.
The |
operator is used by TypeScript.
{x}
Probably not an option as this is too cryptic. Suggested in #151 .
from typing import Optional as O
orfrom typing import Optional as Opt
This is not actually a new syntax and works currently. These are arguably inelegant.
Metadata
Metadata
Assignees
Labels
No labels