Skip to content

Releases: microsoft/pyright

Published 1.1.329

27 Sep 00:31
Compare
Choose a tag to compare

Behavior Change: Added new configuration switch disableBytesTypePromotions that is off by default except in strict mode, when it's on by default. When enabled, it eliminates the old (poorly-documented) behavior whereby bytes when used in a type annotation automatically implies the union bytes | bytearray | memoryview. For details, refer to PEP 688. The configuration switch allows code bases to retain the old behavior, but it's likely that the default value of this option will change to true in the future.

Behavior Change: Improved handling of types float and complex, which are special-cased in PEP 484 as "promotion types". The new logic now properly models the runtime behavior for isinstance and class pattern matching when used with these promotion types.

Behavior Change: Added check for the use of an ellipsis for a default argument value for a function that is not in a stub, not overloaded, and without a placeholder implementation.

Bug Fix: Fixed false positive error that occurs when a member of a frozen dataclass is overridden in a subclass. In this case, the type should not be considered invariant because the field isn't mutable.

Bug Fix (from pylance): Fixed recent regression that caused import resolution issues when using UNC paths and symlinks.

Bug Fix: Fixed several issues with logic that performs protocol matching against a module, including a false positive error when matching against a generic protocol.

Bug Fix: Fixed bug in type compatibility checks for LiteralString. It should not be considered compatible with str or a specific literal str in an invariant context.

Bug Fix: Fixed a false positive error with the reportUnnecessaryComparison check when a recursive type alias is used.

Bug Fix: Fixed a bug in the handling of __match_args__ in class pattern matching. Pyright was using the subject's class rather than the pattern's class to look up __match_args__.

Bug Fix: Fixed a bug in the handling of class pattern matching for subclasses of int, str or other stdlib classes that implicitly supply __match_args__ and return self for matches.

Enhancement: Added a check for class pattern matches where the number of positional patterns exceeds the number of positional fields supported by the class.

Enhancement: Improved error message for type compatibility for list and dict types, which enforce invariance. The new error message now suggest the use of Sequence and Mapping, respectively.

Published 1.1.328

20 Sep 00:57
Compare
Choose a tag to compare

Behavior Change: Added code to enforce invariance of class-scoped variables in overrides when the reportIncompatibleVariableOverride rule is enabled.

Bug Fix: Fixed bug that results in import resolution errors when symlinks are used.

Bug Fix: Fixed a bug that caused a typing.deprecated decorator not to be marked as such.

Bug Fix: Fixed a bug that resulted in a false positive error when *args and **kwargs are passed as arguments to a function with a ParamSpec and the types of *args and **kwargs is Any.

Bug Fix: Fixed bug that caused @deprecated message not to be passed through a ParamSpec.

Bug Fix: Fixed a bug that results in incorrect type narrowing for a mapping pattern if the subject type is a superclass of Mapping, such as object.

Bug Fix: Fixed inconsistent behavior of @deprecated between overloaded and non-overloaded functions.

Bug Fix: Improved validation of generator return type. Previously, the check was performed only for yield statements, but it's possible to define a generator function that has no reachable yield statements.

Bug Fix: Fixed bug that led to a false positive error when checking for out-of-bounds tuple accesses if the indexed type is a union that includes both a bounded tuple and an unbounded tuple.

Behavior Change: Updated the synthesized pop method for TypedDict so its signature is consistent with the synthesized get method. This eliminates an Unknown in some cases.

Bug Fix: Fixed bug that led to incorrect generation of Unknown type evaluation when an overloaded function is called in a loop and one of the arguments to the call depends on the return value.

Enhancement: Updated typeshed stubs to the latest version.

Bug Fix: Fixed a regression that caused an Unknown to appear in a type evaluation when using nested constructor calls.

Published 1.1.327

13 Sep 01:29
Compare
Choose a tag to compare

Bug Fix: Fixed a bug in the isinstance type narrowing logic that evaluated the incorrect type when two protocol classes are involved.

Bug Fix: Fixed a bug that led to a false positive error when enclosing ... in quotes when specifying a ParamSpec default value.

Bug Fix: Fixed bug that resulted in false positive error when using a Union[*Ts] value in a binary expression.

Bug Fix: Fixed a recent regression that caused the pythonPath received from the client to be corrupted resulting in import resolution errors.

Behavior Change: Updated class specialization logic to conform to latest draft of PEP 696 when a class type parameter has a default type and that class is bound to one of its methods.

Enhancement: Improved error message for type argument mismatch when in an invariant context.

Behavior Change: Changed behavior to allow a class variable within a protocol to be marked Final without assigning a value to it in the protocol definition.

Bug Fix: Fixed a bug that results in a spurious error under certain circumstances when evaluating the type of a parameter within a nested function whose type refers to an outer-scope type variable.

Enhancement: Added check for a conditional expression that evaluates to a coroutine, which always evaluates to True. This is likely indicative of a missing await keyword.

Enhancement: Improved the type narrowing logic for the len(x) == L type narrowing pattern for tuples. The new logic supports narrowing of tuples with an indeterminate length (a ... entry).

Behavior Change: Removed check for empty body of @overload function.

Bug Fix: Fixed a false positive error when a TypeVar with a default value (as specified in PEP 696) appears within a method after an outer-scoped TypeVar without a default value.

Bug Fix: Fixed a bug that led to a false positive error when a frozen dataclass has an explicit __eq__ method and is used in way that requires it to be Hashable.

Bug Fix: Improved error messages that include module names. Previously, there were inconsistencies in how module names were reported.

Bug Fix: Fixed false positive error when using a forward-declared reference inside of an inlined TypedDict when from __future__ import annotations is in effect.

Bug Fix: Fixed a bug that led to a false negative when using a non-TypedDict base class within a TypedDict class statement.

Published 1.1.326

06 Sep 01:59
Compare
Choose a tag to compare

Bug Fix: Fixed a bug in the recently-introduced deprecateTypingAliases feature that resulted in false positives when Counter, OrderedDict and ChainMap were imported from collections.

Bug Fix: Fixed a bug that led to a false positive when an enum literal annotation is used within the enum class definition and from __future__ import annotations is in use.

Bug Fix: Added code to mark symbols as accessed if they're imported directly into a class scope using a from x import y statement.

Bug Fix: Fixed a bug that resulted in a false positive error when assigning an unpacked TypeVarTuple to an unpacked tuple[Any, ...] in an invariant context.

Bug Fix: Fixed bug that results in a false positive error during protocol matching when a NamedTuple is matched against a protocol using _fields or other attributes defined in the NamedTuple class.

Bug Fix: Fixed bug that led to a false positive error when determining whether the target of an awaited call is a NoReturn.

Behavior Change: Changed the default of useLibraryCodeForTypes from false to true in the LSP settings. (It was changed to true in all other places previously, but this case was missed.)

Bug Fix: Fixed a bug that led to an incorrect type evaluation in certain cases where a type argument for a function call argument type is left unspecified (and is therefore assumed to be Unknown).

Bug Fix: Fixed a bug that led to incorrect type narrowing for isinstance when the pre-narrowed type is a generic callable.

Bug Fix: Improved determinism of bidirectional type inference for dictionary, list, set and tuple expressions when the expected type is a union of types that includes more than one plausible candidate. The types in the union are now sorted so type evaluation doesn't depend on the order in which the union was defined.

Enhancement: Updated typeshed stubs to the latest version.

Bug Fix: Fixed bug that led to a false negative when @typing.deprecated is used on an async function.

Bug Fix: Fixed a bug that led to the incorrect type evaluation of a constructor call when bidirectional type inference is used and the expected type is a union that includes more than one compatible instance type.

Bug Fix: Fixed a deviation from the PEP 702 spec which indicates that when @deprecated is applied to an overloaded function implementation, that deprecation is meant to apply to all overloads.

Enhancement: Improved error message for deprecated methods.

Enhancement: Improved "no matching overloads" error message in cases where an argument is unpacked.

Enhancement: Added support for custom metaclasses that inject instance variables into the classes they construct.

Published 1.1.325

30 Aug 02:41
Compare
Choose a tag to compare

Bug Fix: Fixed a bug in the isinstance type guard logic that produced incorrect results when narrowing a generic class instance.

Bug Fix: Fixed a bug in the parser that led to a false positive syntax error when a match statement was followed by a - or ~ token.

Bug Fix: Improved logic that determines whether an object is callable. The __call__ attribute must be a class variable, not an instance variable.

Bug Fix: Improved isinstance and issubclass narrowing in the case where an intersection type is created and one of the two subclasses has a custom metaclass.

Behavior Change: Changed type evaluation behavior for a class variable that uses Self in its type definition. When accessed via a subclass (either through cls or self), the type is now assumed to be changed to Self of the child class. This makes pyright's behavior closer to mypy's in this case.

Bug Fix: Fixed regression that resulted in incorrect type evaluation and a spurious reportUnknownArgumentType error when calling the same constructor multiple times in a single call expression.

Bug Fix: Fixed a bug that caused a "py.typed" marker file to be ignored in a namespace package if the marker file is at the same directory level as the submodule being imported leading to a spurious reportMissingTypeStubs error.

Bug Fix: Fixed a bug that led to a false positive during overload matching when the arg type includes a union where one of the subtypes is a constrained TypeVar.

Enhancement: Added a new configuration option deprecateTypingAliases that enables deprecation detection and reporting for symbols imported from the typing module that are deprecated according to PEP 585 and 604. The option is currently disabled by default (even in strict mode) but can be enabled manually.

Behavior Change: Changed logic to exempt abstract overloaded methods within an ABC so an implementation is not required.

Bug Fix: Fixed check for illegal use of zero-argument super within an inner function located within a method.

Bug Fix: Fixed a bug that led to a false negative when a type annotation contains a stringified type on the LHS of an index expression.

Enhancement: Added support for @type_check_only decorator.

Enhancement: Improved error message for type incompatibility when type parameter is covariant or contravariant.

Enhancement: Updated typeshed stubs to the latest.

Bug Fix: Fixed a bug that led to incorrect type evaluation and false positive errors when a function with a ParamSpec was passed to another function with a ParamSpec.

Behavior Change: Changed interpretation of ... forms of tuples to improve consistency and match mypy's behavior. The type tuple[int, ...] is now interpreted as the union of all tuples of length zero or more that contain only int. Because this is a union, assigning a value of this type to a tuple type with a known (specified) length is now considered a type violation.

Bug Fix: Fixed several bugs in the logic for "strict type guard" positive and negative type narrowing.

Bug Fix: Fixed long-standing bug that caused various problems (including poor performance, incorrect type evaluations, and false negatives and false positives) when calling a constructor for a generic class within the class implementation.

Bug Fix: Fixed a bug that led to a false positive reportUnusedVariable error when a dynamic expression was used in a namedtuple call argument.

Bug Fix: Fixed a bug that led to a false positive reportIncompatibleMethodOverride error when a function-scoped type variable was used in a contravariant position.

Bug Fix: Fixed bug that led to the incorrect type evaluation when calling a generic function and a value of type P.args or P.kwargs is assigned to a type variable.

Bug Fix: Fixed a bug that led to a false negative error for an expression used within an f-string within a loop.

Published 1.1.324

23 Aug 00:52
Compare
Choose a tag to compare

Bug Fix: Fixed a bug that led to a false positive error under certain circumstances when a callable using Concatenate is assigned to another callable using Concatenate.

Bug Fix: Fixed bug that can result in a false positive error when a wildcard import targets a module that doesn't contain a __all__ definition but includes dundered names in its module namespace.

Bug Fix: Fixed a false positive error when invoking a call of a variable that is annotated using a PEP 695 type alias.

Bug Fix: Fixed a bug that caused an incorrect application of a ParamSpec in certain cases where the signature bound to the ParamSpec was generic.

Enhancement: Improved validation of NamedTuple and namedtuple factory calls.

Enhancement: Improved detection of redundant pattern capture targets in case statements.

Bug Fix: Changed the type evaluation logic for the enum value member so a custom value type can be specified in the Enum subclass.

Bug Fix: Fixed a bug that led to a false positive in the reportIncompatibleMethodOverride check in certain circumstances where the method in both the base class and child class are overloaded.

Bug Fix: Fixed bug that resulted in a false positive error when an async function with no return type annotation was called recursively.

Bug Fix: Fixed a bug that led to a false positive in the reportIncompatibleMethodOverride check when overriding a method with a ParamSpec.

Bug Fix: Fixed a recent regression that resulted in a false positive during protocol matching if the protocol defines an __eq__ method but doesn't include a __hash__ definition.

Bug Fix: Fixed bug that sometimes led to false positives or false negative in call expressions that involve keyword arguments followed by an unpacked.

Bug Fix: Fixed a bug that resulted in the incorrect textual form (used in error messages) for a generic class with a ParamSpec that is parameterized with ....

Bug Fix: Fixed regression that caused a spurious error with the reportIncompatibleMethodOverride check when a method with a ParamSpec was overridden by a method with *args: Any, **kwargs: Any.

Bug Fix: Fixed a bug that led to incorrect type narrowing on assignment in certain cases.

Enhancement: Added check for classes that have mutually-incompatible base classes due to generic type argument mismatches.

Bug Fix: Fixed bug that led to a false positive reportIncompatibleVariableOverride error when overriding a synthesized __hash__ symbol.

Bug Fix: Added heuristic to constraint solver logic to better handle the case where a parameter is annotated with a union of multiple "bare" TypeVars (like S | T). In this case, it's not clear whether the corresponding argument type should constrain S or T or both. We now defer the constraint during the first pass of arg/param type validation so additional references to S or T can help establish the appropriate constraint.

Bug Fix: Fixed a bug that led to incorrect type evaluation of Union[*Ts] (where Ts is a TypeVarTuple) in certain situations

Bug Fix: Fixed bug that resulted in incorrect type evaluation when passing a generic class as a Callable parameter more than once in the same call.

Enhancement: Added logic to mirror the (rather surprising) runtime behavior when an attribute is accessed from a class object and the metaclass defines an attribute of the same name that happens to be a descriptor object. The runtime favors the metaclass attribute in this case.

Enhancement: Extended inlined TypedDict prototype to support TypedDict as well as dict so we can compare the two proposals.

Bug Fix: Changed logic for handling the __get__ method of a descriptor so pyright more accurately models the runtime behavior when the descriptor is accessed through an object (as opposed to a class). Previously, pyright was modeling this as an Any value to avoid problems with type stubs that are not accurately modeling the runtime behavior, but this caused other unintended side effects.

Bug Fix (from Pylance): Fixed bug that led to internally-corrupted type state if the language server canceled a type evaluation request at just the wrong time.

Enhancement: Added logic to handle the case where a declared return type of a function includes a constrained TypeVar and a return statement is guarded by a case statement using a class pattern that guarantees that the constraint is met on that code path.

Published 1.1.323

16 Aug 03:53
Compare
Choose a tag to compare

Bug Fix: Fixed a condition in the code flow engine that corrupted internal state and led to a crash.

Bug Fix: Fixed bug that resulted in incorrect type evaluation for an async function that has no type annotations. It was using call-site return type inference but failing to wrap the result in a Coroutine.

Enhancement (from Pylance): Added support for ".jar" files for import targets.

Bug Fix: Fixed bug that led to false negative when assignment expression (walrus operator) is used in a yield or yield from statement without a parenthesis.

Bug Fix: Fixed a bug that resulted in incorrect type evaluation (and a false positive error) when a binary operator overload method was annotated to return NoReturn.

Enhancement: Updated typeshed to the latest. This update includes some changes to the two-parameter form of the get method for dict and TypedDict that may result in visible type evaluation changes in some code bases.

Enhancement: Added a check for hashability for objects used as dict keys. Contribution from @TheTripleV.

Bug Fix: Fixed a bug that resulted in a false positive reportUnnecessaryComparison error when the subject of a match statement was mutated in a loop.

Enhancement: Added special-case handling of enum fields that are callables, which are apparently not treated as enumerated types.

Enhancement: Added check to enforce a generator's "send type" in a yield from statement.

Enhancement: Added special-case logic for fields with the name __hash__ within a dataclass.

Enhancement: Added support for ... in the last type argument of Concatenate. After much discussion (see python/cpython#30969), it has been decided to support this even though a strict reading of PEP 612 seems to exclude it.

Bug Fix: Fixed a bug that led to a false negative when assigning a dictionary literal expression to a TypeVar bound to a TypedDict.

Bug Fix: Fixed a bug that led to a false negative when a TypeVar was used inappropriately in certain cases.

Bug Fix: Fixed bug in protocol matching that led to an incorrect protocol match with a NamedTuple. Fields in a NamedTuple are implicitly read-only, so a writable protocol should not match.

Enhancement: Added type compatibility enforcement for symbols imported via a wildcard import.

Enhancement: Added support for indexing into tuples of indeterminate length as long as the index is positive and falls within a determinate portion.

Bug Fix: Fixed type narrowing bug that affected the A is B type narrowing pattern when A has the type type.

Bug Fix: Fixed false positive where an inner function within a method uses a TypeVar to annotate its parameter. The variance of the TypeVar shouldn't be checked in this case, whereas it should be for the method.

Bug Fix: Fixed a bug that led to a false positive when accessing a cached_property defined on an enum.

Bug Fix: Fixed a bug in import resolver that caused a site-packages module to be preferred over a local module if the site-packages package is "py.typed".

Bug Fix: Fixed bug that led to a false positive when a two-argument form of a super call used type as the first argument.

Published 1.1.322

11 Aug 16:35
Compare
Choose a tag to compare

This is a hot fix release to address a regression in 1.1.321.

Bug Fix: Fixed recent regression that led to a false positive when assigning a union of types that use invariant type parameters to a protocol that uses a covariant type parameter. This fix was already incorporated into this week's preview release of pylance (v2023.8.21), so it shouldn't affect pylance users.

Bug Fix: Fixed a bug that led to a spurious "Unknown" type when an assignment to a variable with a type annotation was used within a loop.

Bug Fix: Fixed false positive error when an empty tuple was used in an except statement.

Published 1.1.321

09 Aug 02:38
Compare
Choose a tag to compare

Behavior Change (from pylance): Import suggestions are filtered when py.typed is available based on whether the symbol is considered public or private.

Bug Fix: Fixed a bug that led to a false positive in certain cases where a ParamSpec captures an overloaded function signature.

Bug Fix: Fixed a bug that resulted in a type evaluation error when using bidirectional type inference with a non-generic protocol.

Bug Fix: Fixed a bug that resulted in an off-by-one error in an error message when reporting the index of a mismatched overload.

Bug Fix: Fixed a bug that resulted in a false positive reportIncompatibleMethodOverride diagnostic when the base method used a double underscore to indicate position-only parameters but the override used the newer / separator.

Bug Fix: Revert "Fixed a bug that led to a false negative when determining whether two base classes that are combined using multiple inheritance implement the same method in an incompatible way. The bug caused the check to be skipped if the child class also implemented the same method as the two base classes.

Bug Fix: Fixed a bug that resulted in an incorrect hover type (and inlay hint) for the inferred return type of an async function or method.

Performance: Addressed a performance regression introduced in 1.1.314 due to a switch from ts-loader to esbuild-loader in our build pipeline. This change resulted in a 7-9% performance degradation, so I'm reverting it for now.

Enhancement: Added check for improper use of a type alias defined using the type statement introduced in PEP 695.

Bug Fix: Fixed bug that led to a false positive error in certain cases when using bidirectional type inference when the expected type includes a protocol that is specialized with a literal type argument.

Bug Fix: Fixed a bug that led to incorrect type narrowing on assignment in certain cases where the declared type includes a type argument with an Any and the assigned type does not.

Published 1.1.320

02 Aug 02:46
Compare
Choose a tag to compare

Bug Fix: Reverted new version of chalk library. The newer version is not compatible with node v12.

Bug Fix: Fixed a bug that resulted in a false positive error when attempting to assign a TypeVar T that has a bound of type to an expression type[S].

Enhancement: Added a new configuration options flag called enableExperimentalFeatures that controls whether certain experimental features are enabled. Currently there are three features under this flag: StrictTypeGuard, ReadOnly fields for typed dicts, and inlined TypedDict definitions.

Enhancement: Removed support for experimental StrictTypeGuard and replaced it with an experimental variant of TypeGuard that applies strict semantics if certain conditions are met.

Bug Fix: Fixed a bug that led to incorrect variance inference when a value annotated with a class-scoped TypeVar was assigned to an instance variable.

Behavior Change: Updated heuristics for how to handle custom metaclass __call__ methods based on feedback. Previously, if a metaclass __call__ method was present, pyright assumed that __new__ and __init__ may not be called, so it ignored them. The new heuristic assumes that if the metaclass __call__ returns a type that is consistent with the expected return type of type.__call__ that it is probably mirroring the behavior of type.__call__ and calling the class' __new__ and __init__ methods.

Behavior Change: Changed auto-variance algorithm to exempt class and instance variables that are named as protected or private.

Bug Fix: Fixed a regression that caused class decorators of generic classes to no longer be specializable.

Bug Fix: Fixed a bug that resulted in an apparent hang within the type printing logic. This was triggered by a pathological case involving a deeply recursive type.

Behavior Change: Modified type inference logic so methods that raise an exception whose type derives from NotImplementedError is not inferred to return NoReturn. Previously, only NotImplementedError was exempted, not subclasses.

Behavior Change: Removed old code that looks for a typeshed override in the standard python search paths. This works around an issue with the inject library, which installs a bogus typeshed directory into site-packages.

Bug Fix: Fixed a bug that results in unsolved type variables in a call return if the target function's return type is a callable that has type variables that are scoped to that callable.

Bug Fix: Fixed a bug that resulted in incorrect type evaluation when a generic function that returns a callable is passed itself as an argument and the resulting callable is then called and passed that same function as an argument.

Bug Fix: Fixed a bug in the command-line version of pyright where it did not enable "auto search paths", so it didn't automatically add "src" as an extra path.

Bug Fix: Fixed a bug that led to a false negative when determining whether two base classes that are combined using multiple inheritance implement the same method in an incompatible way. The bug caused the check to be skipped if the child class also implemented the same method as the two base classes.

Bug Fix: Fixed a bug that resulted in a false positive error when using an unpack operator within a call to an overloaded function.

Bug Fix: Fixed a bug that resulted in a false positive error when a captured variable within an inner scope (function or lambda) is imported from another module using an import statement that comes after the function or lambda.

Bug Fix: Fixed bug that led to incorrect type evaluation when accessing the name attribute on an enum.