Skip to content

[Feature request] Allow pipe ( "|" ) to be used as a shortcut for Union  #5178

@ksamuel

Description

@ksamuel

Union are a very common situation when typing code, but they require an import every time. I usually can get away with str/int/float or my own classes for most of the code, but end up making an import just for Union, Dict and List.

The idea would be to allow Union to be expressed with a "|", replacing the Union:

from typing import Union

def multiply(*values: Union[int, float]) ->  Union[int, float]:

Would become:

def multiply(*values: int|float) ->  float|int:

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