github microsoft/pyright 1.1.359
Published 1.1.359

latest releases: 1.1.361, 1.1.360
14 days ago

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.

Don't miss a new pyright release

NewReleases is sending notifications on new releases.