-
However weird it sounds, For such code:
running
The only difference being How do I make this type assert work? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If you want to test for type assignability, then x: Callable[[int], tuple[int,...]] = tuple_of_nums |
Beta Was this translation helpful? Give feedback.
-
SO link https://stackoverflow.com/questions/79437137/assert-type-with-callable |
Beta Was this translation helpful? Give feedback.
assert_type
tests for type equivalency, not type assignability. The type oftuple_of_nums
is(n: int) -> tuple[int, ...]
. The type described by the annotationCallable[[int], tuple[int, ...]]
is a subtype of this type, but it's not equivalent because it does not accept a keyword argumentn
.If you want to test for type assignability, then
assert_type
isn't the right tool to use. You can instead simply include an assignment, and a type checker will verify assignability.