From 320a0a2fd31e4ffc69d4bd96d7202bbe8d8cb410 Mon Sep 17 00:00:00 2001 From: Eric Traut Date: Thu, 29 Apr 2021 08:20:19 -0700 Subject: [PATCH] Updated documentation to indicate that some forms of subscripts are supported in type guards. --- docs/type-concepts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/type-concepts.md b/docs/type-concepts.md index 43b9f678a..9ce7d2059 100644 --- a/docs/type-concepts.md +++ b/docs/type-concepts.md @@ -145,7 +145,7 @@ In addition to assignment-based type narrowing, Pyright supports the following t * `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. +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, subscripts that are constant numbers (e.g. `a[2]`), and call expressions. Other operators (such as arithmetic operators or other subscripts) are not supported. Some type guards are able to narrow in both the positive and negative cases. Positive cases are used in `if` statements, and negative cases are used in `else` statements. (Positive and negative cases are flipped if the type guard expression is preceded by a `not` operator.) In some cases, the type can be narrowed only in the positive or negative case but not both. Consider the following examples: