Commit Graph

4282 Commits

Author SHA1 Message Date
Eric Traut
7e3e52f9c7 Fixed a bug in type evaluation of a Final class variable that has no explicit type but is assigned a literal value. 2021-12-14 15:17:33 -08:00
Eric Traut
db2e5ab9d6 Fixed bug that resulted in a false positive error indicating that an overload isn't compatible with its implementation when the overload includes a callable parameter with a type variable as a parameter. 2021-12-13 21:19:24 -08:00
Eric Traut
01ae3bf97c Improved isinstance type narrowing logic to retain type arguments in cases where the corresponding type parameter is bound or constrained. 2021-12-13 16:21:01 -08:00
Eric Traut
78f2a94943 Added check for a module used as a type annotation, which is not permitted. 2021-12-13 15:31:07 -08:00
Eric Traut
2f616204d9 Added documentation for pyright's overload matching algorithm. 2021-12-13 15:00:17 -08:00
Eric Traut
c9647b9a03 Modified behavior of overload matching when unpacked argument is present and the unpacked iterator is a type that doesn't provide any length information. In this case, overload matching will prefer an overload that includes a *args parameter rather than individual positional parameters. 2021-12-13 13:43:48 -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
179fd1c4aa Modified behavior for assignment-based type narrowing when the target of the assignment references an "asymmetric" descriptor or property, one where the setter accepts a different value type than the getter returns. When this is detected, assignment-based type narrowing is no longer applied. 2021-12-12 14:41:17 -08:00
Eric Traut
693b16dafd Added support for Python 3.11 StrEnum. 2021-12-11 16:49:42 -08:00
Eric Traut
ce9629647e Published 1.1.195 2021-12-10 23:16:59 -08:00
Eric Traut
69c9a4cea7 Improved isinstance type narrowing when the original type is a generic class with a TypeVar as a type argument and the second argument to isinstance is a generic subclass of the original type. The type argument is now properly retained. 2021-12-10 22:53:47 -08:00
Eric Traut
9dc84178c8 Changed type completeness report (the "--verifytypes" feature) to exempt symbols that derive from "__slots__" entries. 2021-12-10 22:23:53 -08:00
Eric Traut
28694ecd1a Fixed bug related to ParamSpec specialization when the signature has zero parameters. 2021-12-10 21:22:41 -08:00
Eric Traut
118ce120a9 Refactored canAssignTypeToParamSpec into its own function to improve readability and maintainability. No functional change. 2021-12-10 21:08:14 -08:00
Eric Traut
5845935e62 Cleaned up types used to track function parameters. No functional change. 2021-12-10 19:14:55 -08:00
Eric Traut
a8d600bad4 Added check for an attempt to call a module, which generates an exception at runtime. 2021-12-10 17:45:39 -08:00
Eric Traut
8be047a5be Fixed a bug that caused a false positive error under certain circumstances where a function return type annotation referred to a forward-declared symbol and from __future__ import annotations was in effect. 2021-12-10 01:01:18 -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
28bdaa70ca Simplified the typeGuards module so it doesn't depend on any knowledge of flow nodes. No functional change. 2021-12-09 22:43:13 -08:00
Eric Traut
c49e6343ee Fixed false positive when using a generic type alias that refers to a class with a __getitem__ method. 2021-12-09 18:43:52 -08:00
Eric Traut
ce8675d309 Fixed style issue. 2021-12-09 17:52:40 -08:00
Eric Traut
af8ece666c Fixed false positive error with reportUnnecessaryComparison diagnostic rule when one of the two operands is type or Type[Any] and the other is a class. 2021-12-09 17:10:56 -08:00
Eric Traut
38dad822cb Fixed bug in handling of __slots__. Entries listed in __slots__ apply only to instance variables, not to class variables. 2021-12-09 15:07:27 -08:00
Eric Traut
fcab8004ba Published 1.1.194 2021-12-08 22:38:35 -08:00
Eric Traut
45b186c5fa Fixed a bug that resulted in a false positive error when a dictionary literal was passed to a constructor of a generic subclass of dict. 2021-12-08 22:36:18 -08:00
Eric Traut
0277d7a108 Added error check for the use of a generic class as a metaclass. 2021-12-08 21:45:31 -08:00
Eric Traut
87bc6630ec PEP 484 indicates that Type[Any] should be interpreted as equivalent to type, but the previous code was treating it as Any. 2021-12-08 21:38:22 -08:00
Eric Traut
282b32a915 Added code to support __qualname__ in class definitions. 2021-12-08 21:07:59 -08:00
Eric Traut
bd588d9729 Fixed a bug whereby an explicit TypeAlias definition that includes a generic type with no explicit type arguments was not assuming Unknown for those type arguments. For example, A: TypeAlias = list should assume that A is equivalent to list[Unknown].
Added a missing diagnostic for an attempt to specialize a class that has already been specialized. This can occur in the case of a type alias, such as `A = list[int], A[int]`.
2021-12-08 20:14:30 -08:00
Bill Schnurr
b81cc63e20
pull pylance: smart indent fixes, dependency update (#2682)
1. Co-authored-by: Bill Schnurr <bschnurr@microsoft.com>
  2. Co-authored-by: HeeJae Chang <hechang@microsoft.com>
  3. Co-authored-by: Erik De Bonte <Erik.DeBonte@microsoft.com>
2021-12-08 15:48:25 -08:00
Eric Traut
c938d54efa Fixed bug that resulted in false positive when a variable was modified in a loop that employed conditional type narrowing and was also used as a member access expression. 2021-12-08 12:12:25 -08:00
Eric Traut
9e96b5858d Updated install instructions for command-line to reference community-maintained package. 2021-12-08 09:16:48 -08:00
Eric Traut
c7082e0550 Fixed a bug that caused type narrowing to fail in certain cases when the "X in Y" type guard pattern was used. 2021-12-08 08:41:37 -08:00
Eric Traut
6d33d281a3
Fixed bug that resulted in the import resolution paths retrieved from the currently-selected Python interpreter to omit the working directory if it happens to be in the "sys.path" list. (#2677)
Co-authored-by: Eric Traut <erictr@microsoft.com>
2021-12-08 00:39:54 -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
c7e4d3badf Fixed bug in specialization of callable type where the return type includes the expansion (unpacking) of a variadic type variable. 2021-12-08 00:10:07 -08:00
Eric Traut
301751c2fb Moved the logic for handling the specialization of generic type aliases into its own function. No functional change. 2021-12-07 23:35:41 -08:00
Eric Traut
d24a31a3a5 Added support for explicit specialization of generic type aliases that include a ParamSpec. 2021-12-07 00:04:21 -08:00
Eric Traut
0739679b0e Fixed inconsistency in definition provider where it would sometimes fail to go to a declaration if the symbol was not re-exported from a type stub or "py.typed" module. 2021-12-06 10:12:32 -08:00
Eric Traut
275956d3d1 Published 1.1.193 2021-12-06 00:22:49 -08:00
Eric Traut
98ea9124f8 Enhanced reportIncompatibleMethodOverride diagnostic check to also detect incompatible methods defined by two classes that are used as base classes in a multiple-inheritance derived class. 2021-12-05 23:28:24 -08:00
Eric Traut
0303cb711f Fixed bug that resulted in false positive when the implementation of a generic class A[T] allocated an instance of itself by calling its own constructor with an argument of type T. 2021-12-05 15:49:58 -08:00
Eric Traut
ae8fda6886 Fixed style issue. 2021-12-05 14:21:05 -08:00
Eric Traut
920095d12d Fixed a bug in the handling of generic classes whose implementation includes another instantiation of itself using the original type parameters as type arguments for the nested instantiation. 2021-12-05 13:16:18 -08:00
Eric Traut
7e038bfeb2 Fixed bug that resulted in TypeVar not being solved in some circumstances involving recursive types. 2021-12-05 12:25:32 -08:00
Eric Traut
8ceedaa3c1 Added optimization in logic that replaces TypeVars with their solved forms. The previous code was generating unnecessary copies of types, which resulted in more memory usage than necessary. 2021-12-05 12:21:11 -08:00
Eric Traut
f1c018b516 Fixed bug in TypeVar solver where Self type was being incorrectly replaced with its concrete form in some cases. 2021-12-05 12:20:12 -08:00
Eric Traut
58aa300287 Renamed isSynthesizedSelfCls field to isSynthesizedSelf for clarity. No functional change. 2021-12-05 12:06:53 -08:00
Eric Traut
1eb9ccd181 Fixed bug that resulted in "unknown" type evaluation for variables assigned in a loop using a tuple assignment pattern. 2021-12-04 10:36:14 -08:00