Skip to content

Union(Type) and TypeForm #21910

Description

@zedzhen

My function should analyze types.
Both when --warn-unreachable is enabled, and when checking typing.Union, and when checking types.UnionType, an error occurs.

code:

from types import UnionType
from typing import Any, Union

from typing_extensions import TypeForm


def f(t: TypeForm[Any]) -> Any:
    if isinstance(t, Union):
        pass


def g(t: TypeForm[Any]) -> Any:
    if isinstance(t, UnionType):
        pass

errors:

main.py:8: error: Argument 2 to "isinstance" has incompatible type "<typing special form>"; expected "_ClassInfo"  [arg-type]
main.py:14: error: Statement is unreachable  [unreachable]
Found 2 errors in 1 file (checked 1 source file)

in runtime, the behavior of both isinstance is equivalent.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions