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 or from typing import Optional as Opt
This is not actually a new syntax and works currently. These are arguably inelegant.
Multiple people have suggested a shorter syntax to replace
Optional[...]. The current syntax will become more inconvenient if we don't infer optional types fromNonedefault values (see #275).Here are various options that I remember seeing proposed:
x?or?xThis would require new Python syntax.
Hack uses
?x. TypeScript usesx?for names, not types, if I've understood things correctly.x | NoneThis 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 Oorfrom typing import Optional as OptThis is not actually a new syntax and works currently. These are arguably inelegant.