Skip to content

Can't pass a value of type Union[str, bytes] to a generic function typed with AnyStr #1533

Description

@gvanrossum

Repro:

from typing import AnyStr, Union
def g(a: AnyStr) -> AnyStr:
    pass
def f(a: Union[str, bytes]):
    g(a)

We get an error on the last line:

c.py:5: error: Type argument 1 of "g" has incompatible value "Union[str, bytes]"

I would have expected that it would just deduce that y is also a Union[str, bytes].

(UPDATE: shortened the repro.)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions