Skip to content

Overloads with None don't work #1399

Closed
Closed
@bdarnell

Description

@bdarnell

This example (straight out of the PEP, in a stub file instead of a source file) doesn't pass mypy's type checking:

from typing import overload

unicode = str

@overload
def utf8(value: None) -> None:
    pass
@overload
def utf8(value: bytes) -> bytes:
    pass
@overload
def utf8(value: unicode) -> bytes:
    pass
/tmp/overloadtest.pyi:6: error: Overloaded function signatures 1 and 2 overlap with incompatible return types
/tmp/overloadtest.pyi:6: error: Overloaded function signatures 1 and 3 overlap with incompatible return types

It looks like None is being interpreted as something broader, when at least for overload resolution it just means the exact value None and shouldn't overlap with any non-optional type.

Related to #885.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions