Skip to content

Releases: microsoft/pyright

Published 1.1.366

05 Jun 04:10
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a false positive error under certain circumstances involving a call to a higher-order generic function with another function that involves a class with a contravariant type variable.
  • Fixed bug that results in a confusing error message when stub generation fails.
  • Fixed bug that results in false positive when evaluating the call to a generic function that involves a type variable used in both a covariant and contravariant (or invariant) position and both literal and non-literal types are involved.
  • Fixed bug that results in a false negative when solving a type variable that involves an invariant context.
  • Fixed a bug that can result in incorrect type inference for a subexpression that is part of an assignment expression if executed with an inference context (bidirectional type inference).
  • Fixed bug in x is E type narrowing pattern where E is an enum literal and x is a supertype of E like object.

Behavior Changes:

  • Changed behavior of constructor call evaluation when __new__ evaluation results in type evaluation errors. Previously, pyright skipped the __init__ evaluation in this case. It now proceeds to evaluate __init__, potentially generating redundant errors.
  • Removed support for inlined TypedDict annotations. This was an experimental feature that never gained enough support to make it into a PEP.
  • Changed behavior of pyright to match the latest typing spec when it encounters an attribute with a type annotation within an Enum class body in a stub. These are now treated as non-member attributes rather than members. Typeshed stubs have been updated to conform to the new standard.
  • Added diagnostic check for an enum member with a type annotation. The typing spec says that this should be considered a typing error.

Enhancements:

  • Updated typeshed stubs to the latest version.

Published 1.1.365

29 May 04:18
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed regression that results in the incorrect type evaluation for the value attribute of a StrEnum or IntEnum class.
  • Fixed a bug that results in incorrect type compatibility checks for a callable that uses *args: *tuple[T, *tuple[S, ...]].
  • Fixed a bug that results in an unsolved TypeVar when calling list(tuple()).
  • Fixed bug that leads to inconsistent narrowing-on-assignment behavior when a tuple instance with unknown type arguments is assigned to a target symbol with a declared tuple type.
  • Fixed bug that results in a false negative when a Final class variable is assigned a value in the class body and reassigned a value in the __init__ method.

Behavior Changes:

  • Changed tuple expression inference behavior to not preserve literal entry types if the tuple expression is embedded within another tuple, set, list, or dictionary expression.
  • [Contribution by @ujan-r] Use typeshed version info for stdlib module list.

Enhancements:

  • Improved diagnostic messages for parameter mismatch.
  • Added support for configuration inheritance through an "extends" configuration option.
  • Added support for custom ".toml" files specified via the -p option on the command line.

Published 1.1.364

22 May 02:13
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a false negative syntax error when a PEP-695 type alias uses a keyword as a name.
  • Fixed a bug that leads to a false positive error when first argument to super call is an instance of a metaclass.
  • Fixed recent regression that results in a false positive when accessing an enum member from an instance of an enum class.
  • Fixed bug that results in a false negative when determining if a callable type is compatible with another callable type and the first has a *args parameter and the second has a single positional+keyword parameter.
  • Fixed a bug in the code flow engine that results in incorrect type evaluation in certain cases involving codependent variables in a loop.
  • Fixed a bug that results in incorrect type narrowing for a type guard function that uses TypeIs[type[T]].
  • Fixed regression related to "converter" field parameter for dataclasses when the converter refers to a generic class constructor.
  • Fixed a bug that results in a false negative when a generic function has a parameter with a generic type and a default argument value. This could lead to a typing hole when considering subtyping rules for callables.
  • Fixed a bug in the dataclass "converter" support that resulted in an error if the converter is tuple.
  • Fixed regression that results in incorrect type evaluation for annotations that involve nested protocols (such as P[P[T]]).
  • Fixed a bug that resulted in an infinite loop when a function that uses an *args: *Ts parameter is passed as an argument to itself.
  • Fixed bug that leads to a false negative when calling a callback function that returns a callable with a generic parameter type.

Behavior Changes:

  • Changed the handling of Enum subclasses that explicitly override value or name to avoid using the special-case logic for computing these types. This is done regardless of whether the class uses a custom metaclass.
  • Changed support for dataclass "converter" field parameter to be off by default. The "enableExperimentalFeatures" must now be enabled to use this feature. If and when PEP 712 is approved, it will be moved out of experimental.
  • Added support for using Literal and various other special forms in a value expression.

Enhancements:

  • Added support for recent addendum to typing spec that provides a special case for dataclasses so ClassVar and Final can be used together to distinguish between a regular Final instance variable and a ClassVar that is also Final.
  • Updated typeshed stubs to the latest version.
  • Improved type printer (the component that converts an internal type to textual format for diagnostic messages) so it better handles special forms like Literal or unions when used in a value expression.

Published 1.1.363

15 May 05:02
Compare
Choose a tag to compare

Bug Fixes:

  • Updated manifest to reflect the correct default value for reportInvalidTypeForm.
  • Fixed bug that resulted in diagnostics associated with the reportUnnecessaryTypeIgnoreComment check to not include the error code.
  • Fixed bug that causes a false positive reportPrivateUsage error when a global or nonlocal binding is used within a class to access an outer-scoped variable.
  • Fixed bug that results in a false positive reportUnnecessaryComparison when a variable is used in a conditional expression and its type is a union that includes a Coroutine and a non-coroutine.
  • Fixed false positive deprecatedTypingAliases deprecation for collections.abc.AbstractSet due to a recent change in typeshed stubs.
  • Fixed recent regression that results in assert_type failure when a class is parameterized by a ParamSpec with a default value.
  • Improved handling of constrained TypeVars when used with unary operators.
  • Fixed bug that results in incorrect type narrowing for a tuple with determinate length when indexed with an out-of-bounds slice.
  • Fixed bug that results in incorrect type narrowing for isinstance or issubclass type guard when the filter is a generic class whose type parameter has a default value.
  • Fixed bug that results in incorrect type evaluation behavior within class body of an enum class when one enum member is used to define another enum member. This involved a significant rewrite of the logic involving enum symbol evaluation.
  • Fixed a bug that results in a false positive error when a decorator is applied to a property.
  • Fixed bug that resulted in false positive when evaluating a function call involving a TypeVarTuple under certain circumstances.
  • Fixed a bug that results in incorrect type evaluation when a function parameterized with a TypeVarTuple is passed as an argument to another function parameterized with a TypeVarTuple.

Behavior Changes:

  • Deferred execution of type annotations (PEP 649) did not make it into Python 3.13 and has been deferred (again) until Python 3.14. Changing pyright's logic accordingly.
  • Changed the type evaluation for type(Any) or type(x) where x is a value of type Any or Unknown. These now evaluate to type[Unknown].
  • Changed the TypeVar scoping behavior for TypeVars that appear only within a Callable subtype within a function's declared return type. Previously, pyright scoped these TypeVars to the Callable rather than the function. This was due to issue #4285. I'm reversing this decision because it's not spec-compliant, creates a bunch of unnecessary complexity, and results in buggy behavior.

Published 1.1.362

08 May 05:43
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that results in incorrect type narrowing when a match statement uses an empty (zero-element) sequence pattern and the subject expression type is a tuple that potentially (but does not always) have a zero length.
  • Fixed a crashing bug that results from an internal assertion failure when a generic class that uses PEP 695 syntax is located within an unreachable code block.
  • Fixed a bug that results in incorrect type narrowing in the negative (fall-through) case when a match statement includes a class pattern with a runtime-checkable protocol class.
  • Fixed recent regression with the TypeIs type guard that resulted in incorrect type narrowing in the negative (else) case.
  • Fixed a bug that results in incorrect type evaluation for a variable that uses a nonlocal or global binding within an inner scope. Such a variable should never honor the narrowed type from the outer scope.
  • Fixed false positive when a TypeVar appears within a function type comment.
  • Fixed incorrect type narrowing for a class pattern argument if the class is a generic whose type parameters have default values.
  • Fixed recent regression that resulted in incorrect type narrowing when a *args: P.args parameter was used in the expression len(args) >= x.
  • Fixed a bug that resulted in a false negative when a Literal with multiple arguments is used in a value expression. It should be treated as a UnionType special form in this case.

Enhancements:

  • Addressed a performance issue when indexing into a value that has a type consisting of a union of many (dozens or hundreds) of tuple types.
  • Updated typeshed stubs to the latest version.

Behavior Changes:

  • Changed interpretation of function definitions with (*args: Any, **kwargs: Any) to be ... in compliance with latest typing spec.
  • Added special-case handling for __init_subclass__ checks for classes that have ABCMeta as a metaclass. Previously, these were exempted from __init_subclass__ because ABCMeta has a custom __new__ method, but we know that this metaclass calls through to type.__new__ which calls __init_subclass__.

Published 1.1.361

01 May 01:57
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that results in a false negative when using bidirectional type inference to evaluate the type of a lambda expression if the expected type is a union of two or more callables.
  • Fixed bug caused by incorrect synthesis of item and keys attributes for named tuple classes.
  • Fixed bug that resulted in incorrect bidirectional type inference when calling a constructor for a generic class that defines no __new__ or __init__ method.
  • Fixed bug that results in a false positive error when a yield statement is used within a lambda following a function.
  • Fixed a bug that led to poor performance (effectively a hang) if an unannotated function is called through many (greater than 8) call expressions within a loop using different literal-value arguments each time.
  • Fixed a bug that results in a false positive error when using __extra_items__ (PEP 728) with a TypedDict imported from typing_extensions.
  • Fixed a bug that leads to an infinite loop when performing protocol matching under certain circumstances that involve recursive protocol definitions.
  • Fixed a bug that results in a false positive error when Callable() is used as a class pattern and the subject type is Any or Unknown.
  • Fixed a false negative that occurs when reassigning a Final variable within a class body.
  • Changed the tokenizer so it is bug-for-bug compatible with the CPython tokenizer in versions 3.10 and newer in the case where a backslash (continuation character) is located by itself on a line.
  • Fixed a bug that results in incorrect type evaluation when a global (module-scoped) variable is captured within an inner scope and the variable is not modified anywhere below the inner scope. It's possible in this case for the variable to be modified by code outside of the module.
  • Fixed bug that resulted in incorrect evaluation of an identifier used in a method parameter type annotation if it shadows a forward reference in a class scope when the method is using PEP 695 type parameters.
  • Fixed a bug that results in a false negative when an Unpack is used in a union. This isn't allowed.
  • Fixed bug that produces incorrect output when converting to a textual representation the type type[Foo] where Foo is a type alias.

Behavior Changes:

  • Changed logic that synthesizes the constructor methods for a NamedTuple subclass (using the class syntax) so the __new__ method contains parameters based on field names and the __init__ method contains a general *args: Any, **kwargs: Any parameter signature. Previously, this was swapped, but the new way is more faithful to the runtime.
  • Changed TypeIs to use the same logic as isinstance type narrowing logic for consistency.

Published 1.1.360

24 Apr 05:07
Compare
Choose a tag to compare

Enhancements:

  • Added support for @deprecation messages for decorators that wrap a function in a callable object. The deprecated message is now propagated through the ParamSpec and the __call__ method.
  • Updated typeshed stubs to the latest version.

Behavior Changes:

  • Moved check for invalid use of class-scoped TypeVar within a self annotation in __init__. It was previously reported under reportGeneralTypeIssues, but it's now moved to reportInvalidTypeVarUse. This was done to help typeshed maintainers migrate away from this pattern.
  • Changed behavior to no longer exempt unguarded access to not-required TypedDict member within a try or with block. Previously, such errors were exempt, but this is inconsistent with other type checks in pyright which eschew the practice of using exception handling for normal code flow.

Bug Fixes:

  • Fixed recent regression that affected unannotated __call__ methods in a metaclass. This change aligns pyright's behavior to the typing spec.
  • Fixed recent regression that incorrectly narrowed the type of kwargs when used in a type guard of the form if "a" in kwargs.
  • Fixed bug in protocol matching that results in a false positive when the subject object is a dataclass that contains a callable. It should be considered an instance member in this case, so it should not be bound to the class.
  • Fixed a bug that results in a false positive error when bidirectional type inference is used for a dictionary comprehension when the expected type is a union.
  • Redesigned the handling of PEP 695-style type parameter scoping to better match the CPython runtime implementation. This fixes multiple bugs with type parameter symbol resolution. For example, if a type parameter is quoted as a forward reference.
  • Fixed bug that leads to false negative when binding an object to an overloaded method where all of the overloads have incompatible self parameter types.
  • Fixed bug that leads to incorrect metatype for a class object that is created by calling the metaclass with a two-argument form.

Published 1.1.359

17 Apr 00:23
Compare
Choose a tag to compare

Enhancements:

  • Expanded support for len(x) == L type guard pattern (where x is a tuple) to support <, <=, > and >= comparisons as well.
  • Improved some diagnostic messages, moving away from the term "member" to prefer "attribute". Switched from "cannot assign to type" to "incompatible with type" for consistency and clarity.
  • Extended type narrowing logic for in and not in operators that target TypedDicts to also support constrained TypeVars that use TypedDicts as value constraints.
  • Added a check for the case where a frozen dataclass overrides a field from its parent class but doesn't provide a default value (where its parent does). This can result in a type violation if the parent's default value is not compatible with the child's (covariant) field type.

Behavior Changes:

  • Changed behavior when evaluating the upper bound expression, value constraints expression, or default expression for a PEP-695 type parameter. At runtime, these are always evaluated in a deferred manner even if they are not quoted. Pyright now follows the runtime behavior.
  • Modified handling of annotated self parameter in __init__ method when evaluating constructor call so pyright conforms to the latest typing spec.
  • Added missing check for the errant use of class-scoped type variables in a type annotation for the "self" parameter within an "init" method. The typing spec now clarifies that this is illegal and should generate an error.
  • Updated logic for converting a class constructor to a callable to conform to the newly-updated typing spec.
  • Changed the behavior when invoking constructor for type[T] where T is a TypeVar with no explicit upper bound (and therefore has an implicit upper bound of object). According to the newly-clarified typing spec, this should enforce the constructor signature of object.
  • Modified behavior in constructor call code that previously applied some (now non-compliant) heuristics to reconcile a metaclass __call__ method with a __new__ method. The new behavior is now compliant with the typing spec.
  • Changed behavior of conversion from class constructor to callable to conform with the typing spec in the case where the __new__ method of the class returns a value that indicates the __init__ method should be ignored.
  • Changed behavior of conversion from class constructor to callable to conform to honor the annotated type of self in the __init__ method.
  • Changed behavior of conversion from class constructor to callable to conform to honor return type of the __new__ method.

Bug Fixes:

  • Fixed a bug that leads to inconsistent behaviors when an assignment leads to a type violation. When assigning to a local variable, the target expression is not "narrowed" to include the assigned type in this case. The new behavior applies this same behavior when assigning to instance or class variables.
  • Fixed recent regression that results in a false positive error when applying a @property decorator to a method that has already had a decorator applied to it.
  • Fixed bug that results in a spurious reportAbstractUsage error when an abstract class is captured through a type[T].
  • Fixed bug that results in incorrect type evaluation when solving a ParamSpec type when there are multiple constraints provided.
  • Fixed a bug that results in incorrect type evaluation when assigning a function with a NoReturn return type to a Callable[..., T].
  • Fixed a bug that leads to a false negative when an unparenthesized assignment expression is used in a dictionary key within a dictionary expression or comprehension.
  • Fixed bug that results in false positive error under certain circumstances that involve unions of TypeVars in an invariant context.

Published 1.1.358

10 Apr 02:38
Compare
Choose a tag to compare

Bug Fixes:

  • (from Pylance): Fixed a bug that caused a crash under certain circumstances when an import cannot be resolved.
  • Fixed non-compliance issue with TypeIs, which is documented to have an invariant type parameter.
  • Fixed a bug that results in incorrect type evaluation when a sequence pattern in a match statement includes a * element and the subject includes a tuple with an element with indeterminate length.
  • Fixed bug that results in an intermittent false positive "circular dependency" error for fields within a dataclass.
  • Fixed a bug that results in a false positive error under certain circumstances when a TypeVar or TypeVarTuple is being solved with literal values in both an invariant and non-invariant context.
  • Fixed bug that results in incorrect type evaluation in cases where a generic function returns a callable, and the function is called with a higher-order generic function as an argument.
  • Fixed a bug that results in a false negative when a generic function returns a Callable type that is specialized to include a live (in-scope) type variable.
  • Fixed bug that results in inconsistent type narrowing on assignment based on whether the assignment occurs within the same statement that includes the (declared) type annotation for the variable and whether the type annotation is provided as a type comment.

Enhancements:

  • Added optimization for TypedDict type assignments. Under certain circumstances (e.g. when comparing large unions of TypedDict types), this can save significant time.
  • Modified the handling of enum class attributes so those with private (mangled) names are exempted from being considered enum members. This reflects the runtime behavior.
  • Added support for narrowing of subject subexpression within a match statement for references to the subexpression after the completion of the match statement.
  • Updated typeshed stubs to the latest version.
  • Improved error handling for quoted annotations. Bytes, raw strings, and f-strings are not allowed according to the typing spec.
  • Added an error message for a Literal type annotation that includes a string with a named unicode escape sequence. These are not supported.

Published 1.1.357

03 Apr 14:56
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a false positive error when explicitly calling __new__ on a dataclass, namedtuple, or TypedDict. These classes all require synthesized __new__ methods.
  • Fixed bug that results in false negative when a __new__ or __init__ method cannot be bound without a type violation.
  • Fixed a bug that results in incorrect type narrowing of enums that derive from enum.Flag.
  • Fixed a type hole when a dictionary expression includes a dictionary expansion operator that acts on a non-closed TypedDict.
  • Fixed bug that results in a type not being narrowed when using the K in TD type guard pattern (where TD is a TypedDict and K is a literal key). Narrowing was skipped if the RHS operand was not a simple identifier.
  • Fixed inconsistent handling of literal values in a list comprehension.
  • Fixed a bug that results in a false positive error when an unpacked TypeVarTuple is used in a function defined with PEP-695 syntax.
  • (From Pylance) Improved heap usage tracking within language server to reduce the likelihood of crashes related to heap exhaustion.
  • Fixed a bug that results in incorrect inferred parameter types for an unannotated method in a subclass when the parent class method contains function-scoped TypeVars.

Enhancements:

  • Added support for negative (fall-through) type narrowing for subject subexpressions in match statement when subject consists of a tuple expression and patterns exhaustively match the tuple.
  • Enhanced dictionary type evaluation to support dictionary items that overwrite previous dictionary items. Only the last value type is now considered, so if previous values (which are overwritten) would otherwise violate typing rules, this no longer generates a type error.
  • Enhanced discriminated class support to include not only literal field values but also None.
  • Improved diagnostic message for access to unknown member in the case where the user probably meant to access an item in a TypedDict but used a member access expression rather than an index expression.
  • Improved return result for synthesized get method for closed TypedDict classes (as defined in PEP 728).
  • Refactored tokenizer and parser output to help reduce the amount of memory needed.

Behavior Changes:

  • Changed the handling of Final variables (that are not explicitly marked ClassVar) within dataclass class bodies. This is consistent with the runtime and this proposed change to the typing spec.