Skip to content
Prev Previous commit
Next Next commit
Add tests
  • Loading branch information
srittau committed Apr 8, 2026
commit 7b3519a7d09e6af6921136c0ed0b3317af2c6bae
34 changes: 33 additions & 1 deletion stdlib/@tests/test_cases/check_functools.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from functools import cache, cached_property, wraps
from functools import _SingleDispatchCallable, cache, cached_property, singledispatch, wraps
from typing import Callable, TypeVar
from typing_extensions import ParamSpec, assert_type

Expand Down Expand Up @@ -108,3 +108,35 @@ class CachedChild(CachedParent):
@cache
def method(self) -> Child:
return Child()


def check_singledispatch_simple() -> None:
@singledispatch
def sd_fun(arg: object) -> str:
return ""


@sd_fun.register
def _(int_arg: int) -> str:
return ""

assert_type(sd_fun, _SingleDispatchCallable[[object], str])

sd_fun.dispatch(42)
sd_fun.dispatch("")
sd_fun.dispatch(1, 2) # type: ignore


def check_singledispatch_additional_args() -> None:
@singledispatch
def sd_fun(arg: object, posonly: str, /, verbose: bool = False) -> str:
return ""


@sd_fun.register
def _(int_arg: int, posonly: str, /, verbose: bool = False) -> str:
return ""

sd_fun.dispatch(5.4, "")
sd_fun.dispatch(5.4, "", verbose=True)
sd_fun.dispatch(1, 2) # type: ignore
Loading