Skip to content

Commit 7b3519a

Browse files
committed
Add tests
1 parent b50ff5f commit 7b3519a

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

stdlib/@tests/test_cases/check_functools.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from __future__ import annotations
22

3-
from functools import cache, cached_property, wraps
3+
from functools import _SingleDispatchCallable, cache, cached_property, singledispatch, wraps
44
from typing import Callable, TypeVar
55
from typing_extensions import ParamSpec, assert_type
66

@@ -108,3 +108,35 @@ class CachedChild(CachedParent):
108108
@cache
109109
def method(self) -> Child:
110110
return Child()
111+
112+
113+
def check_singledispatch_simple() -> None:
114+
@singledispatch
115+
def sd_fun(arg: object) -> str:
116+
return ""
117+
118+
119+
@sd_fun.register
120+
def _(int_arg: int) -> str:
121+
return ""
122+
123+
assert_type(sd_fun, _SingleDispatchCallable[[object], str])
124+
125+
sd_fun.dispatch(42)
126+
sd_fun.dispatch("")
127+
sd_fun.dispatch(1, 2) # type: ignore
128+
129+
130+
def check_singledispatch_additional_args() -> None:
131+
@singledispatch
132+
def sd_fun(arg: object, posonly: str, /, verbose: bool = False) -> str:
133+
return ""
134+
135+
136+
@sd_fun.register
137+
def _(int_arg: int, posonly: str, /, verbose: bool = False) -> str:
138+
return ""
139+
140+
sd_fun.dispatch(5.4, "")
141+
sd_fun.dispatch(5.4, "", verbose=True)
142+
sd_fun.dispatch(1, 2) # type: ignore

0 commit comments

Comments
 (0)