directives_assert_type_2
error
assert_type() type mismatch
assert_type(expr, Type) is a static-analysis directive that verifies the inferred type of expr equals Type. When the resolver can determine both sides and they do not match, this rule emits an error.
from typing import assert_type
def f(a: int | str) -> None:
assert_type(a, int) # E — int | str is not int
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
directives_assert_type_2 down per-file or per-path from your editor or
pyproject.toml, or fix the code
so it type-checks. See the Type System rules and
the complete diagnostic reference.
Canonical URL: https://www.basilisk-python.dev/errors/directives_assert_type_2