diff --git a/README.md b/README.md index 22e06ab5d..9aa647682 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ Pyright supports [configuration files](/docs/configuration.md) that provide gran * [PEP 604](https://www.python.org/dev/peps/pep-0604/) complementary syntax for unions * [PEP 612](https://www.python.org/dev/peps/pep-0612/) parameter specification variables * [PEP 613](https://www.python.org/dev/peps/pep-0613/) explicit type aliases +* [PEP 647](https://www.python.org/dev/peps/pep-0647/) user-defined type guards * Type inference for function return values, instance variables, class variables, and globals * Type guards that understand conditional code flow constructs like if/else statements diff --git a/docs/type-concepts.md b/docs/type-concepts.md index c48c37200..1e5c4110c 100644 --- a/docs/type-concepts.md +++ b/docs/type-concepts.md @@ -141,7 +141,8 @@ In addition to assignment-based type narrowing, Pyright supports the following t * `isinstance(x, T)` (where T is a type or a tuple of types) * `issubclass(x, T)` (where T is a type or a tuple of types) * `callable(x)` -* `f(x)` (where f is a user-defined type guard that is annotated to return a TypeGuard[T] type) +* `f(x)` (where f is a user-defined type guard as defined in [PEP 647](https://www.python.org/dev/peps/pep-0647/)) + * x (where x is any expression that is statically verifiable to be truthy or falsy in all cases) Expressions supported for type guards include simple names, member access chains (e.g. `a.b.c.d`), the unary `not` operator, the binary `and` and `or` operators, and call expressions. Other operators (such as arithmetic operators or subscripts) are not supported. diff --git a/packages/vscode-pyright/README.md b/packages/vscode-pyright/README.md index f3f2d9cf7..557f5efd0 100644 --- a/packages/vscode-pyright/README.md +++ b/packages/vscode-pyright/README.md @@ -22,6 +22,7 @@ Pyright supports [configuration files](/docs/configuration.md) that provide gran * [PEP 604](https://www.python.org/dev/peps/pep-0604/) complementary syntax for unions * [PEP 612](https://www.python.org/dev/peps/pep-0612/) parameter specification variables * [PEP 613](https://www.python.org/dev/peps/pep-0613/) explicit type aliases +* [PEP 647](https://www.python.org/dev/peps/pep-0647/) user-defined type guards * Type inference for function return values, instance variables, class variables, and globals * Type guards that understand conditional code flow constructs like if/else statements