Skip to content

How to declare a forward type alias in Python 3.8 with recent Union change? #2019

@Azureblade3808

Description

@Azureblade3808

I have been working on Windows 7, which doesn't support Python over 3.8.

I used to write code like

from typing import Union

Alias = Union["Origin"]

def do_something_with_alias(x: Alias):
    ...

class Origin:
    ...

while using Union as a work-around for lack of TypeAlias.

But with the recent change of Union (probably since microsoft/pyright#2479), such usage would cause an error of "Union requires of two or more type arguments".

So, is there another way to accomplish a forward type alias in Python 3.8? Or is it possible to mute this error?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions