A few comments: 1. The current syntax appears to require that TypeGuard only apply to the *first* parameter of a function (ignoring self or cls, if present) but it might be valuable to apply to a different parameter in certain cases. For example: def conforms_to(type: Type[T], value: object) -> TypeGuard[value=T]: ... tentative spelling ^^^^^^ Considering prior art, TypeScript's version of TypeGuard (a "type predicate") allows naming the parameter it applies to: function isNumber(x: any): x is number { ... } I might suggest that a syntax like `TypeGuard[param=T]` be permitted to specify a particular parameter whose type should be narrowed. Note that keyword argument syntax can't be used in square brackets [] unless/until PEP 637 ("Support for indexing with keyword arguments") at [1] is accepted. Also that PEP is currently slated for Python 3.11+ whereas this PEP is currently slated for Python 3.10+. I could potentially see breaking off the addition of keyword syntax to TypeGuard to a later PEP, to avoid making this PEP depend on PEP 637 ("Support for indexing with keyword arguments"). 2. The discussions in the "Rejected Ideas" section of this PEP need some more elaboration IMHO: 2.1. §"Decorator Syntax":
The use of a decorator was considered for defining type guards.
Here, it would be useful to show an example of what the proposed decorator syntax was. Presumably you're referring to the syntax from PEP 586 §"Interactions with narrowing" and Ivan's comment: from typing import * @overload def is_int_like(x: Union[int, List[int]]) -> Literal[True]: ... @overload def is_int_like(x: object) -> bool: ... def is_int_like(x): ... def foo(scalar: Union[int, str]) -> None: if is_int_like(scalar): scalar += 3 # type of 'scalar' should be narrowed to 'int' else: scalar += "foo" # type of 'scalar' should be narrowed to 'str' 2.2. §"Enforcing Strict Narrowing":
Strict type narrowing enforcement was considered, but this eliminates numerous valuable use cases for this functionality.
I don't actually know what this is talking about. [1]: https://www.python.org/dev/peps/pep-0637/ -- David Foster | Seattle, WA, USA Contributor to TypedDict support for mypy