Skip to content

Overload on Optional[str] and bytes fails with arg of type Union[str, bytes] #5204

Closed
@gvanrossum

Description

@gvanrossum

This may well be a known issue. @Michael0x2a. (The real code used os.listdir(), but I'm simplifying it here and it fails the same way.)

@overload
def listdir(a: Optional[str] = None): pass
@overload
def listdir(a: bytes): pass
def listdir(a): pass

def f(a: Union[bytes, str]):
  listdir(a)  # error: Argument 1 to "listdir" has incompatible type "Union[bytes, str]"; expected "Optional[str]"

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions