Skip to content

Releases: microsoft/pyright

Published 1.1.345

08 Jan 03:39
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that led to false negative when a list expression was used within the first type argument of an Annotated type expression.
  • Added a missing error condition for a non-method function that is marked @final.
  • Fixed crash related to a regression introduced with recent internal URI tracking.
  • Fixed false negative for a TypeVarTuple constructor call that includes value constraints.
  • Fixed a bug that led to an incorrect type evaluation for an explicitly-specialized class parameterized with a ParamSpec.
  • Fixed bug that resulted in incorrect type evaluation when a PEP-695 TypeVar is shadowed by an identifier of the same name within an inner scope.
  • Added missing check for inconsistent use of @final in an overloaded function. Added missing check for override of an overloaded method marked @final.
  • Fixed bug in protocol matching logic to reject a protocol match if a variable is a ClassVar in the protocol but not in the concrete class (or vice versa).
  • Fixed bug that leads to a false positive when a generic property is defined within a protocol.
  • Fixed a bug that led to incorrect type evaluation when a constrained TypeVar includes literal types as constraints.
  • Added missing check for the specialization of a generic type alias that includes a TypeVarTuple plus two or more TypeVars.
  • Fixed a bug that resulted in a false negative when specializing a generic type alias parameterized by a regular TypeVar with an unpacked tuple.
  • Added missing error for an illegal unpacked argument in type argument list.
  • Fixed a bug that led to a duplicate error message when defining a class-scoped type alias.

Enhancements:

  • Improved error message for protocol classes that derive from non-protocol classes.
  • Improved error reporting for incompatible overrides.
  • Added code to report when the Concatentate special form is used in an illegal context.
  • Added support for constants for field names in NamedTuple call.
  • Improved evaluation logic for tuple slices. It now works in cases where the tuple includes unbounded entries or unpacked TypeVarTuples.
  • Improved type analysis performance in certain cases involving complex code flow graphs and "truthy" conditional statements.
  • Added check for a call to an unimplemented method in a protocol from a base class that explicitly calls it.
  • Implemented small performance improvement by not generating error messages during protocol TypeVar variance validation.
  • Added check for data protocols used in an issubclass call. PEP 544 indicates that this isn't allowed.
  • Added check for "unsafe overlaps" for a runtime-checkable protocol when used in an issubclass or isinstance check.

Behavior Changes:

  • Changed CLI to sort diagnostics by location within a file.
  • Removed support for Union[*Ts] and Union[*tuple[...]]. This functionality was included in an early draft of PEP 646 but was dropped in the final spec. The functionality can still be used in pyright if useExperimentalFeatures is set to true, but it will likely be removed entirely in the future.

Published 1.1.344

30 Dec 01:04
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that caused "go to definition" and semantic rename to not work for forward-declared symbols referenced in a "type" type alias definition.
  • Fixed bug in parser that resulted in an incorrect syntax error when certain expression forms were used with the type statement to define a type alias.
  • Fixed a bug that resulted in a false negative when attempting to access valid attributes from a type alias created via a call to the TypeAliasType constructor.
  • Fixed a bug that led to an incorrect type evaluation when explicitly specializing a generic class or type alias with a ParamSpec.
  • Fixed a bug that led to a false positive "not awaitable" error if the __await__ method return type was Unknown.
  • Fixed a bug that results in a false negative when the TypeAliasType constructor is called with an expression that refers to a traditional TypeVar.
  • Fixed a bug that leads to a false negative when validating type compatibility between two callables and the source has a position-only parameter corresponding to a non-position-only parameter in the dest.
  • Fixed bug in code flow analysis that resulted in an incorrect type evaluation when a "NoReturn" call is made within a code block protected by an exception-suppressing context manager.

Behavior Changes:

  • Added LSP exemption for __post_init__ method.
  • Improved overload overlap logic to detect partial overlaps when parameter types include unions that intersect.

Enhancements:

  • Improved logic that determines whether the expression used for a type statement or a call to TypeAliasType is a valid type expression.
  • Added additional checks for invalid NewType calls.
  • Improved detection of invalid type alias expressions for implicit (traditional) type aliases.
  • Improved error reporting for with statement when __enter__ or __aenter__ is present but cannot be bound.

Published 1.1.343

26 Dec 04:25
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that resulted in crash when using language server APIs in certain circumstances.
  • Fixed bug that resulted in incorrect type evaluation of a variable within a loop under certain conditions.
  • Fixed a bug in the function type assignment logic that leads to a false positive under certain circumstances involving a ParamSpec in an overload with a callback that includes a positional-only parameter separator.
  • Fixed a bug that leads to a false negative when Self is used within a class definition statement. PEP 637 explicitly rejects this usage of Self.
  • Fixed a bug that leads to a false negative when Self is used within a metaclass. PEP 637 explicitly rejects this usage of Self.

Enhancements:

  • Eliminated some unnecessary work when determining the effective type of a symbol that doesn't have a declared type. When evaluated in the context of a particular usage, it's unnecessary to evaluate any assignments within the same execution scope.
  • Add error checking for illegal use of unary, binary, or ternary operators within a type annotation.
  • Added detection of invalid keyword arguments in TypedDict class definition when using the normal class syntax.
  • Added detection of a call to TypedDict alternative syntax form that assigns the resulting class to a variable whose name doesn't match the name specified in the TypedDict call.
  • Added check for the use of a TypedDict class in an isinstance or issubclass call. These generate a runtime exception.

Published 1.1.342

20 Dec 08:20
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed @deprecated functionality that was broken by a recent change to the typeshed stubs (which replaced a function with a class).
  • Fixed bug that results in a false positive error under certain circumstances when calling an inner function that uses a ParamSpec defined scoped to an outer function.
  • Fixed a bug in the --verifytypes CLI feature that resulted in a false negative when docstrings are missing from a class or function that is defined in a private module but re-exported from a public module.
  • Fixed a bug that led to a combinatoric explosion and an infinite loop in certain edge cases involving a class with an untyped constructor and methods that return recursive types.
  • Fixed a bug that led to false negative errors when doing protocol matching with a method that uses Self in its signature.
  • Increased internal limit of the number of overload signatures that can be captured by a ParamSpec from 64 to 1024.
  • Fixed a bug that leads to infinite recursion (stack overflow) under certain circumstances.

Enhancements:

  • Added narrowing support for literal patterns in a match statement that are used to discriminate between tagged unions of objects that can be discriminated based on a field with a literal type.

Published 1.1.341

15 Dec 19:32
Compare
Choose a tag to compare

Normally, new pyright releases are published each Tuesday. This is an out-of-cycle release that addresses several regressions introduced in 1.1.340. These were all related to a massive change (one that affected a majority of the source files in pyright) that changed the way that file paths were tracked internally. Pyright now uses URIs rather than simple paths β€”Β a change that's needed to support a number of language server features.

Bug Fixes:

  • Fixed regression introduced in 1.1.340 that caused a crash in the --verifytypes functionality.
  • Fixed regression introduced in 1.1.340 that resulted in an incorrect URI returned as part of a language server "rename" request.
  • Fixed regression introduced in 1.1.340 that resulted in an unintended schema change for the outputjson output.
  • Fixed regression introduced in 1.1.340 that resulted in a crash when using file watchers (--watch option).
  • Fixed regression introduced in 1.1.340 that resulted in incorrect import resolution for certain namespace packages.
  • Fixed bug that resulted in a false positive error when one ParamSpec was captured by another ParamSpec.
  • Fixed bug related to function type compatibility when the dest type contains an unpacked tuple followed by one or more positional-only parameters as in Callable[[*Ts, int], None].

Enhancements:

  • Improved signature help provider so it handles overloaded __init__ and __new__ methods when calling a constructor.
  • Updated typeshed stubs to the latest version.

Published 1.1.340

13 Dec 01:20
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed English text for position-only error. It contained an extraneous \" at the end.
  • Fixed a bug that resulted in a crash under certain circumstances when defining a type alias using a type statement when no type parameters are defined.
  • Fixed bug in narrowing logic for sequence pattern magic where special cases of str, bytes, and bytearray were not handled correctly.
  • Fixed bug that led to a false positive when a zero-argument form of super is called within an inner function or lambda.
  • Fixed a bug that led to a false positive error in certain cases involving a union of two callables.
  • Removed implicit __qualname__ attribute from the module namespace. It doesn't exist at runtime, so this was leading to a false negative.
  • Fixed bug that led to a false positive when a tuple of indeterminate length was used in a callback function.
  • Fixed a bug that led to an improper "unbound" type evaluation under certain circumstances in a finally clause.
  • Fixed bug that results in an extraneous } character in stub output.
  • Fixed bug that led to incorrect return type inference for a generator that always raises an exception rather than returning.
  • Fixed package manifest so default values of configurations are properly reflected.

Behavior Changes:

  • (From pylance) All paths are now internally tracked as URIs. This provides better support for files that are not stored within a file system. This should be transparent to most pyright users.
  • Previously, return type inference was disabled for all functions when analyzeUnannotatedFunctions was set to false regardless of whether the function had input type annotations. Return type inference is now enabled if the function is partially annotated.

Enhancements:

  • Improved error message for set invariance type violations.
  • Added support for the @warning.deprecated (PEP 702) functionality when an overloaded function implementation is marked deprecated and then used outside of a call expression.
  • Enhanced type narrowing logic for sequence pattern matching to support narrowing of tuple subject types based on sequence subpatterns.
  • Extended support for "partially unbound" variable detection to cases that involve comprehension and class scopes.
  • Eliminated the limitation that unpack operators, await operators, assignment expressions (walrus operators), f-strings, chained strings, and strings with escape characters cannot be used within Annotated expressions when using an alias of Annotated.

Published 1.1.339

06 Dec 03:29
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that resulted in a false positive error under certain circumstances involving inferred variance, decorators and generic type aliases.
  • Fixed a bug that resulted in a false positive when Self was used in a value expression outside of a class body.
  • Fixed bug that resulted in a false positive error when overriding a TypedDict field when the overridden type was Any or vice versa.
  • Fixed bug that resulted in a false negative when overriding a TypedDict field with an incompatible Required or NotRequired attribute.
  • Fixed recent regression that resulted in a false negative when type or type[Any] was used as a type annotation for a field in a dataclass.
  • Fixed a bug that results in a false positive when anext is passed a value of type AsyncIterator.
  • Fixed recent regression that results in false positive error where type or type[Any] is not considered type compatible with Callable.
  • Fixed bug that affected the case where a TypedDict class derived from two incompatible classes using multiple inheritance. The error was reported in the wrong location.
  • Fixed bug that results in incorrect type evaluation when a raise statement is used within a context manager that swallows exceptions.
  • Fixed bug that led to incorrect type evaluation with unary operator when used with a type alias defined with forward references.
  • Fixed bug that resulted in a crash within the function return type checking logic.
  • Fixed bug that resulted in incorrect type evaluation when del statement is applied to a class member implemented with a descriptor.
  • Fixed regression that resulted in a false negative for the reportUnknownMemberType check when the expression is a call argument and the member is a function with a partially-unknown signature.
  • Fixed a bug that resulted in incorrect type evaluation in certain cases involving generic protocols and bound TypeVars.
  • Fixed a bug in the code flow engine that resulted in a false negative for a variable whose type is narrowed within an inner loop.
  • Fixed bug that led to improper type narrowing for class patterns when Callable is used.
  • Fixed bug that resulted in incorrect narrowed type evaluation in certain circumstances involving certain code flow graph structures.

Enhancements:

  • Added support in dataclass_transform for custom field specifiers that have default arguments for their init or kw_only parameters.
  • Implemented check for inconsistent use of @staticmethod and @classmethod in overloads.
  • Added support for accessing members of a TypeAliasType object.
  • Added an error check for a PEP 695 type statement within a function body. Type alias definitions are not allowed within this scope.
  • Added support for *args: *Ts parameter that captures a callable with an indeterminate number of positional parameters because some of them have default arguments.
  • (Contribution from @jbarrachinab) Improved a few error messages in the Spanish localization.
  • Enhanced support for TypeVarTuple capture of a callable to support literal arguments.
  • Added a few optimizations that help improve perf somewhat when large unions are involved.
  • Added support for doc strings when using the PEP 695 type statement.

Behavior Changes:

  • Added a new typeCheckingMode called "standard". It's a subset of "strict" but a superset of "basic". It is the new default mode, and it should cover all of the required checks for conformance with the Python typing standard.
  • Changed behavior of check for unimplemented methods in a class that explicitly derives from a protocol. If the class also explicitly derives from abc.ABC, it is exempted from this check. This is useful for mixin classes.
  • Changed behavior of reportUnknownMemberType (and other checks in the reportUnknown... family) to not report a partially-unknown type if it refers to an unspecialized class.
  • Moved checks for Required/NotRequired and ReadOnly overrides from reportGeneralTypeIssue to reportIncompatibleVariableOverride for consistency. Added checks for Required/NotRequired and Readonly incompatibilities in the multiple inheritance case.
  • Changed behavior of two-argument form of super when it is used outside of an attribute access expression. It now employs a heuristic whereby it evaluates to the next base class of the bound type.
  • Changed the type printer logic to avoid emitting truncated Literal string and bytes values when it is asked to enforce Python syntax. This mode is used for inlay hints and the stub generator (for inferred return type comments).

Published 1.1.338

29 Nov 06:18
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that results in a false positive error in the reportUnknownMemberType check when abc.Callable (without any type arguments) is used in the second argument to an isinstance call.
  • Fixed bug in literal pattern matching that resulted in incorrect narrowing when the subject was typed with a constrained TypeVar.
  • Fixed bug that led to incorrect conversion from a class constructor to a function when it involves a __new__ method that returns Self.
  • Fixed bug that resulted in crash under certain obscure circumstances where a class with multiple type parameters is explicitly specialized with only a subset of required type arguments.
  • Eliminated some differences between the treatment of type and Type. These should be treated the same under all circumstances.
  • Fixed recent regression that resulted in a false positive when accessing a class property from a class instance.
  • Fixed a bug that can result in spurious false positive errors when using deeply-nested or recursive type definitions such as _NestedSequence in numpy.
  • Fixed bug that led to a false negative when Never is used as an explicit type argument for a generic class or type alias if the corresponding type parameter is a constrained TypeVar.
  • Fixed bug that produces a false negative when attempting to assign a method to a Callable type where the first parameter of the method is typed as Self, but the callback requires the class itself.
  • (from Pylance) Fixed bug that led to false positive errors related to import resolution when a partial stub is used and its directory structure doesn't match that of the library.

Enhancements:

  • Improved error handling for failures when explicitly specializing a generic type alias. Improved diagnostic message for assert_type failures when printed types look the same when not using the full name of the type.
  • Added support for bidirectional type inference for chained assignment expressions.
  • Updated typeshed stubs to the latest version.
  • Added deprecation message for class properties, which were deprecated in Python 3.11 and are going away in Python 3.13.
  • Added support for parameter type inference for lambdas whose parameters include default arguments. This is analogous to the logic used for unannotated function parameters with default arguments.

Behavior Changes:

  • Changed the behavior for empty dict or list expressions. Previously, a variable initialized with {} or [] was not flagged as "partially unknown" by the reportUnknownArgument check when used as an argument to a call. This resulted in a small type hole.
  • Changed type evaluation logic for member access expressions for type[Any] where the target attribute is not explicitly declared in the type or object class. Previously, pyright emitted an error in this case.

Published 1.1.337

22 Nov 03:22
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that resulted in a false positive when applying a descriptor whose __get__ method whose owner parameter is annotated with type[T].
  • Fixed bug that affected the isinstance type narrowing logic when the pre-narrowed type is a type alias that refers to a union that includes a recursive type alias.
  • Fixed bug in completion provider that resulted in incorrect keyword parameter suggestions for positional-only parameters.
  • Fixed bug that led to a spurious "unknown argument type" when passing an unpacked tuple in a call expression.
  • Fixed regression that results in a false positive when using a value of type type[Protocol] as the second argument to isinstance or issubclass if the protocol isn't @runtime_checkable.
  • Fixed regression that resulted in false positive errors when a magic method (e.g. __lt__ or __add__) are implemented with a callable protocol object.
  • Fixed a bug that resulted in a false positive error when using a walrus operator in a call expression that targets an overloaded function.
  • Fixed bug that led to a hang (infinite loop) in the language server when opening a document whose URI wasn't a "file". This occurred in some language servers that used an "untitled" (or similar) URI type for new documents.
  • Modified recent bug fix in isinstance and issubclass type narrowing logic so it better handles type variables with bounds that are unions.
  • Fixed a bug that resulted in a false positive error when a higher-order generic function is passed another generic function as an argument along with another argument that dictates the type of the first argument's type variable(s). This shouldn't depend on the order in which the arguments are passed.
  • Fixed a bug that resulted in a false positive error when a higher-order generic function is passed another generic function as an argument along with another argument that dictates the type of the first argument's type variable(s). This shouldn't depend on the order in which the arguments are passed.
  • Fixed a recent regression that resulted in a false positive error when a parent class defines a property with a getter and a child class extends the property with a setter.
  • Fixed bug that led to an incorrect type evaluation when a list comprehension expression is used with bidirectional type inference and the expected type includes a type variable.
  • Fixed bug that led to a false positive error when a __getitem__ returns Self.
  • Fixed a bug that led to a false positive when determining the type compatibility of two TypedDict definitions whose keys were typed with unions that included two other (compatible) TypedDict definitions.
  • Fixed a bug that led to incorrect type evaluation when two lists with different types were concatenated using a + operator in a bidirectional inference context.
  • Fixed a bug that results in incorrect type evaluation of an index expression when the LHS is unbound. It should produce Unknown rather than Never.
  • Fixed bug that resulted in a false positive under certain circumstances where a recursive type alias was used and hit an internal recursion limit.

Enhancements:

  • Improved lambda inference logic to handle the case where the expected type is a callable that accepts a generic callable as a parameter.
  • Added error reporting for illegal use of TypedDict or Protocol within a TypeVar bound or within a type annotation.
  • Enhanced reportInvalidTypeVarUsage diagnostic message to include a recommended fix.
  • Added check for the use of a bare Literal (with no type arguments) in places where it's not allowed.

Behavior Change:

  • Adjusted heuristic for reportInvalidTypeVarUse so it doesn't emit a warning when an unbound TypeVar is used within a subscript.

Published 1.1.336

15 Nov 03:14
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in an incorrect type evaluation when functools.partial is used with a constructor where type[Self] is passed as the first argument.
  • Fixed bug that resulted in a crash during type analysis.
  • Fixed bug that results in false positive when indexing an enum class.
  • Fixed a bug that led to a false positive error when calling the same generic function multiple times in a call expression. This bug specifically affected the case where the generic function used PEP 695 syntax.
  • Fixed a bug that led to a false negative when a subclass overrides a parent class with an overloaded method in an incompatible manner.
  • Fixed bug in the import resolver that allowed typeshed stubs and stub files within installed third-party libraries to take precedence over local modules.
  • Fixed a bug that leads an incorrect type evaluation when binding a magic method (like __add__) to self when the magic method returns Self.
  • Fixed a bug that resulted in an incorrect type evaluation when accessing a property that returns Self or type[Self].
  • Fixed bug that resulted in incorrect type evaluation of a symbol imported twice by two redundant wildcard imports.
  • Fixed a bug that leads to a false positive reportPrivateUsage diagnostic when importing a public symbol from a "py.typed" library if that symbol is imported from a private symbol (and re-exported publicly) within the library.
  • Fixed a bug that led to incorrect type evaluation when an inferred method return type includes a union where the subtypes are conditioned on constraints of a constrained TypeVar that parameterizes the class. In this case, one or more of these subtypes should be eliminated when a specialized class is bound to the method.
  • Add support non english works in docstring arguments.
  • Fix bug in the contravariant return type check where a contravariant used in a union was not reported.

Behavior Changes:

  • Changed behavior when converting a class to a callable. If the class has no __init__ or __new__ method in its class hierarchy (other than those provided by object), pyright previously converted the constructor to a signature of (*args: Any, **kwargs: Any). It now converts it to a signature of () (i.e. no params) unless it's a type[T] or a protocol class.
  • Modified the isinstance type narrowing logic to retain a TypeVar when narrowing in the positive case and the value is not a constrained TypeVar.

Enhancements:

  • Added "metacls" as an allowed name for the "cls" parameter in a metaclass __new__ method.
  • Improved pyright's enforcement of keyword arguments passed within a class statement when the class has no custom metaclass or __init_subclass__ in its hierarchy. In this case, the object.__init_subclass__ method applies, and it accepts no additional keyword arguments. Also improved the error reporting for __init_subclass__ in general.
  • Improved handling of + operator when both operands are tuples. It now produces a more accurate type when one (but not both) of the two tuples is of indeterminate length.
  • Updated typeshed stubs to the latest version.
  • Added code to CLI to verify file specs passed on the command line. If they don't exist, emit an error and a non-zero exit code.
  • Improved check for second argument to isinstance and issubclass so non-runtime-checkable protocol classes are rejected.
  • Added special-case handling x in y narrowing logic for the case where x is a dict or Mapping and y is an iterable of TypedDicts.
  • Added check for the use of contravariant TypeVars in an inferred return type.