Skip to content

Incompatible return value type with TypeVar #10003

Description

@marouane-miftah

mypy=0.800
python=3.8.6

The following code generates
error: Incompatible return value type (got "str", expected "Union[ndarray, T]")

from __future__ importannotationsfromtypingimportTypeVar, UnionimportnumpyT=TypeVar("T")
def_test(a: list[T]) ->Union[numpy.ndarray, T]:
ifisinstance(a[0], str):
returna[0]
returnnumpy.array(a)

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