Skip to content

Shorter syntax for Optional[...] #429

Closed
@JukkaL

Description

@JukkaL

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:

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

  1. x | None

This would require support for | for all type objects, which would not be backward compatible.

The | operator is used by TypeScript.

  1. {x}

Probably not an option as this is too cryptic. Suggested in #151 .

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions