returns_compatibility
error
Return type mismatch
Emitted as an Error when the literal value returned by a function is clearly incompatible with the declared return type annotation (e.g. returning an int literal from a -> str function).
# BAD (return type mismatch)
def count() -> str:
return 42 # E: int literal is not assignable to str
# GOOD
def count() -> int:
return 42
How to handle it
Every rule is on by default — strict is the default, not a cage. You can dial
returns_compatibility 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/returns_compatibility