Open Ben621 opened 2 weeks ago
This has come up before; I think it's a mypy limitation. AFAICT, static checkers special-case symbols like overload
and singledispatch
. For example, replacing
singledispatch = multimethod
@singledispatch
...
gives your expected error.
i still dont't Get ERROR. i get SUCCESS
from typing import reveal_type
from multimethod import multimethod
singledispatch = multimethod
@singledispatch
def func(value: int | list [int]) -> None:
raise NotImplemented
@func.register
def _(value: list[int]) -> list[int]:
return list(map(lambda x: x +1, value))
@func.register
def _(value: int) -> int:
return int(func([value])[0])
if __name__ == "__main__":
print(func(1))
print(func([3]))
print(func("3"))
print(func(["ff"]))
reveal_type(func(["ff"]))
mypy blah.py
Success: no issues found in 1 source file
Try adding from functools import singledispatch
.
Describe the bug When i run mypy on my code i don't get error only success
Success: no issues found in 1 source file
To Reproduce
blah.py
mypy
:mypy blah.py
output:
note:
func(["ff"])
andfunc("3")
are invalid valueExpected behavior expected to get
error: Argument 1 to "func" has incompatible type "str"; expected " int | list [int]"
Version