PEP 742: Narrowing types with TypeIs
This PEP proposes a new special form, TypeIs, to allow annotating functions that can be used to narrow the type of a value, similar to the builtin isinstance . Unlike the existing typing.TypeGuard special form, TypeIs can narrow the type in both the if and else branches of a conditional.