narrowing_typeis
error
TypeGuard/TypeIs return type incompatibility in callable arguments
When a function returning TypeGuardX or TypeIsX is passed as an argument where the expected callable return type is NOT bool, this rule reports the mismatch. TypeGuard and TypeIs are subtypes of bool in callable context, so passing them where Callable..., bool is expected is valid, but passing them where e.g. Callable..., str is expected is an error.
def takes_callable_str(f: Callable[[object], str]) -> None: ...
def simple_typeguard(val: object) -> TypeGuard[int]: ...
takes_callable_str(simple_typeguard) # E0112 — TypeGuard is bool, not str
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
narrowing_typeis 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/narrowing_typeis