Skip to content

mypy error with generics typing and singledispatch #19564

@ruomad

Description

@ruomad

Hello,

Is this normal ?

code
`
from functools import singledispatch
from typing import Any

@singledispatch
def test[T: Any](val: T)-> None:
print("default")

@test.register
def _(val: str) -> None:
print("str")

@test.register
def _(val: float) -> None:
print("float")
`
yields these errors from mypy

Dispatch type "str" must be subtype of fallback function first argument "T"
Dispatch type "float" must be subtype of fallback function first argument "T"

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