|
1 | 1 | from __future__ import annotations |
2 | 2 |
|
3 | | -from functools import cache, cached_property, wraps |
| 3 | +from functools import _SingleDispatchCallable, cache, cached_property, singledispatch, wraps |
4 | 4 | from typing import Callable, TypeVar |
5 | 5 | from typing_extensions import ParamSpec, assert_type |
6 | 6 |
|
@@ -108,3 +108,35 @@ class CachedChild(CachedParent): |
108 | 108 | @cache |
109 | 109 | def method(self) -> Child: |
110 | 110 | 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