Commit Graph

54 Commits

Author SHA1 Message Date
Eric Traut
9c8a0f1a4a Improved error message for set invariance type violations. This comes from mypy issue https://github.com/python/mypy/issues/16631. 2023-12-07 10:52:16 -08:00
Eric Traut
c83a95e62e More improvements to documentation. 2023-03-07 16:38:22 -07:00
Eric Traut
1fdeadeca6 Improved "getting started" documentation. 2023-03-07 09:53:49 -07:00
Eric Traut
b3fd962116 Fixed bugs in documentation. 2023-03-06 15:45:51 -07:00
Eric Traut
81f21ee3d4 Added support for type guard patterns type(x) == T and type(x) != T. This addresses https://github.com/microsoft/pyright/issues/4719. 2023-03-01 23:29:44 -07:00
Eric Traut
f8eb114de3 Fixed a few typos in the pyright documentation. 2023-02-01 08:09:36 -08:00
Eric Traut
a2784020f2 Added support for x[K] is V and x[K] is not V type narrowing forms. This addresses https://github.com/microsoft/pyright/issues/4453. 2023-01-13 16:53:18 -08:00
Christian Clauss
bd3ac8b722
Fix typos discovered by codespell (#4399) 2023-01-04 06:54:43 -07:00
Eric Traut
c7626944f1 Added support for type guard forms x is ..., x is not ..., x == ... and x != .... Support for these were recently added to mypy. This addresses https://github.com/microsoft/pyright/issues/4397. 2023-01-04 06:13:44 -07:00
Eric Traut
775b7b4d85 Improved handling of TypeVars that appear only within a Callable within a return type annotation for a function. By a strict reading of PEP 484, these should be bound to the function's scope, but practically, they are bound to the Callable. This allows a function to return a generic callable type. When TypeVars are rescoped in this manner, the TypeVar cannot be referenced within the function body because it is no longer in scope in that context. This addresses https://github.com/microsoft/pyright/issues/4285. 2022-12-25 10:57:02 -07:00
Eric Traut
c4e61dcc6a Fixed a few bugs in the type guard documentation. 2022-12-18 15:10:30 -08:00
Eric Traut
8d3a6e62c8 Further clarified the new overload behavior in the documentation. 2022-12-18 08:06:47 -08:00
Eric Traut
1dc84b93b1 Modified the overload matching algorithm to match the behavior of mypy when the overload match is ambiguous because an argument evaluates to Any or Unknown. In this case, the call expression evaluates to Unknown. Previously, pyright used the first of the matching overloads in this case. This addresses https://github.com/microsoft/pyright/issues/4347. 2022-12-16 23:18:37 -08:00
Ignacio Vergara Kausel
512df5e922
Update type-concepts.md (#4099)
Fixed typo in documentation.
2022-10-27 06:05:31 -07:00
Eric Traut
d5d27505ef Updated types in documentation to use PEP 604 syntax. 2022-10-24 20:06:21 -07:00
Kwanghoon Choi
40d511fadc
Update type-concepts.md (#4029)
A fix to add a missing parameter to isinstance as:
 - isinstance(val, Bar)
2022-10-09 23:24:19 -07:00
Eric Traut
f2328237d3 Extended the "X in Y" type narrowing to support dict, defaultdict and OrderedDict classes. 2022-05-30 00:55:22 -07:00
Eric Traut
255497446a Fixed bug in type narrowing logic for expressions of the form "X not in Y". 2022-05-29 23:54:15 -07:00
Eric Traut
8d5da97ba6 More doc improvements. 2022-05-08 11:12:37 -07:00
Eric Traut
9f08b64bcd Added documentation for class and instance variables. 2022-05-08 11:09:48 -07:00
Eric Traut
3b5752431b Extended type guard for discriminated literal fields to support properties. 2022-04-29 20:39:32 -07:00
Eric Traut
8660a6f870
Added support for type guard based on a.b is None or a.b is not None patterns where b is a member variable that distinguishes two different classes. (#3273)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2022-04-01 11:06:53 -07:00
Eric Traut
d1e5c924bd Revert "Add support for type narrowing of NamedTuple fields with "is None" (#3271)"
This reverts commit e296cd58ee.
2022-03-29 20:02:54 -06:00
Kevin Coffey
e296cd58ee
Add support for type narrowing of NamedTuple fields with "is None" (#3271)
* Add support for type narrowing of NamedTuple fields with is None.

* Add description for `x.y is None` narrowing

Fix capitalization for filename of sample in test.
2022-03-29 19:59:55 -06:00
Eric Traut
a4900ebd03 Extended support for narrowing of index expressions to include those with negative subscripts, such as a[-1]. This is supported for all supported type guard patterns. 2022-03-05 01:35:17 -07:00
Eric Traut
4d75f59065 Fixed typo in documentation. 2022-02-19 14:11:16 -07:00
Jelle Zijlstra
3cc4e6ccdd
Document reveal_type() and reveal_locals() (#2996)
reveal_locals() was not documented anywhere, which may be part of why so few people know about it.

Happy to put this somewhere else if you prefer.
2022-02-05 19:21:30 -08:00
Eric Traut
b69843cf03 Updated type inference documentation to eliminate a statement that was leading to some confusion. 2022-01-27 13:20:55 -08:00
Eric Traut
130c1cc055 Changed type guard logic that involves is operator and literals to be limited to bool and enum literals. It was making unsafe assumptions for other forms of literals. 2022-01-06 09:13:05 -07:00
Eric Traut
4fe3f1f7c0 Improved type narrowing for x == L pattern to include x is L, since they are equivalent. Likewise, extended x.y == L pattern to include x.y is L. 2022-01-05 15:19:37 -07:00
Eric Traut
d74b89a758 Added support for new type narrowing pattern: len(x) == L and len(x) != L where x is a tuple or union of tuples and L is a literal integer value. 2022-01-01 13:31:10 -07:00
Eric Traut
046eab4a8d Added support for bool(x) type guard. 2021-12-31 14:23:56 -07:00
Eric Traut
2f616204d9 Added documentation for pyright's overload matching algorithm. 2021-12-13 15:00:17 -08:00
Eric Traut
211ebe44dd Changed class pattern matching behavior to support narrowing of Any or Unknown, exempting this case from the general "never narrow Any" rule. 2021-12-12 14:54:59 -08:00
Eric Traut
50b31d533f Improved documentation. 2021-12-10 00:06:35 -08:00
Eric Traut
c5788d4916 Implemented support for type guards that are based on a local variable that is assigned an expression that narrows the type of the assigned expression. Some limitations apply. For details, refer to https://github.com/microsoft/pyright/blob/main/docs/type-concepts.md#narrowing-based-on-local-variable. 2021-12-09 23:56:44 -08:00
Eric Traut
e267b8adec Improved handling of x in y type guard to handle the case where y is a tuple. 2021-12-08 00:17:46 -08:00
Eric Traut
cc7216e66e Changed text representation of inferred type of self and cls parameters to Self@ClassName. This is more consistent with the emerging standard for an explicit Self type. 2021-10-29 21:21:32 -07:00
Eric Traut
1cbb690b11 Added support for new type guard pattern: x[I] is None and x[I] is not None where x is a tuple or union of tuples with known lengths and entry types and I is an integer. 2021-10-06 22:48:14 -07:00
Eric Traut
3fa5299614 Changed code that converts types to textual representation to prepend a tilde ("~") character for the inferred type of a "self" or "cls" parameter. 2021-09-24 20:01:48 -07:00
Denis Eliseev
475a44273c
Update type-concepts.md (#2230) 2021-08-26 08:33:12 -07:00
Eric Traut
0bf45ea2ed Added support for new type narrowing pattern for discriminating among tuples. The pattern is V[I] == L or V[I] != L where I is an integer literal, L is another literal value, V is a tuple with a known length and a type at index I that is declared as a literal type. 2021-08-06 23:17:21 -07:00
Eric Traut
0440272219 Added support for type narrowing conditional expressions of the form a is False, a is True, a is not False and a is not True. 2021-06-18 17:01:59 -07:00
Yuichi Tateno (secon)
e09560c3ea
Fixing wrong type int to str of type-concepts.md (#1958) 2021-06-07 15:53:48 -07:00
Eric Traut
0f9d308827 Added documentation for conditional types reported with "*". 2021-05-29 15:43:09 -07:00
Eric Traut
eced7b57bd Added support for "tagged union" type narrowing when the conditional expression is of the form x[K] == V or x[K] != V where x is a union of TypedDict objects and K is a literal str key value that refers to a field with a literal type and V is a literal value. 2021-05-23 23:38:04 -07:00
Eric Traut
c52c928e66 Added type narrowing support for index expressions where the index value is a string literal. 2021-05-23 23:03:05 -07:00
Eric Traut
320a0a2fd3 Updated documentation to indicate that some forms of subscripts are supported in type guards. 2021-04-29 08:20:19 -07:00
Eric Traut
9ac028e7ab Fixed bug in sample code for documentation. 2021-03-07 09:12:54 -08:00
Eric Traut
ee2b18986e Added more documentation for "implied else narrowing". 2021-03-07 09:12:06 -08:00