@@ -118,4 +118,45 @@ class R: ...
118118static_assert(is_equivalent_to(Intersection[tuple[P | Q], R], Intersection[tuple[Q | P], R]))
119119```
120120
121+ ## Callable
122+
123+ ``` py
124+ from typing import Callable
125+ from knot_extensions import CallableTypeFromFunction, is_equivalent_to, static_assert
126+
127+ def c1 () -> None : ...
128+
129+ static_assert(is_equivalent_to(CallableTypeFromFunction[c1], Callable[[], None ]))
130+ ```
131+
132+ Two callable types with the same signature but different parameter names are not equivalent.
133+
134+ ``` py
135+ def f1 (a : int ) -> int : return 1
136+ def f2 (b : int ) -> int : return 1
137+
138+ static_assert(not is_equivalent_to(CallableTypeFromFunction[f1], CallableTypeFromFunction[f2]))
139+ ```
140+
141+ Neither when only one of the callable types has parameter names.
142+
143+ ``` py
144+ static_assert(not is_equivalent_to(CallableTypeFromFunction[f1], Callable[[int ], int ]))
145+ ```
146+
147+ If the default values of the same parameters are different, the types are not equivalent.
148+
149+ ``` py
150+ def f3 (a : int = 1 ) -> int : return 1
151+ def f4 (a : int = 2 ) -> int : return 1
152+
153+ static_assert(not is_equivalent_to(CallableTypeFromFunction[f3], CallableTypeFromFunction[f4]))
154+ ```
155+
156+ Neither when only one of the callable types has default values.
157+
158+ ``` py
159+ static_assert(not is_equivalent_to(CallableTypeFromFunction[f1], CallableTypeFromFunction[f3]))
160+ ```
161+
121162[ the equivalence relation ] : https://typing.readthedocs.io/en/latest/spec/glossary.html#term-equivalent
0 commit comments