Closed
Description
Documentation
In #9865, mypy added support for this pattern.
from typing_extensions import TypeGuard
def is_float(a: object) -> TypeGuard[float]: pass
def main(a: object) -> None:
if is_float(x := a):
reveal_type(x) # N: Revealed type is 'builtins.float'
reveal_type(a) # N: Revealed type is 'builtins.object
I couldn't find examples of this in https://www.python.org/dev/peps/pep-0647/ or in the docs in #10758.
Question
Is this a unique behavior to mypy? Is it something that is expected of all type checkers that implement type guards?
Assuming this wasn't an experimental behavior that will be dropped, it would be helpful to document this usage pattern.