Skip to content

Type inference problem with overloaded mkdtemp #1541

Closed
@JukkaL

Description

@JukkaL

tempfile.mkdtemp returns str (in Python 2) if given no arguments. However, if any of the optional arguments is unicode, the return type should be unicode. We can use an overloaded function to represent this:

@overload
def mkdtemp() -> str: ...
@overload
def mkdtemp(suffix: AnyStr = ..., prefix: AnyStr = ..., dir: AnyStr = ...) -> AnyStr: ...

However, mypy infers type Any for call mkdtemp(), because it thinks that both signatures could match equally well. Instead, mypy should give preference to the first signature.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions