Skip to content

Releases: microsoft/pyright

Published 1.1.375

07 Aug 02:42
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a false positive error when a covariant type variable that is scoped to a method is used in a parameter annotation.
  • Fixed bug that leads to internal data structure corruption and subsequent false positive errors in certain cases involving unions of Unknown types that include type aliases.
  • Fixed bug in the functools.partial logic that results in incorrect handling of an unpacked TypedDict when used with a **kwargs parameter.
  • Fixed bug that results in a false positive reportUnsupportedDunderAll warning when using the __all__.extend(x.__all__) form and the list of entries in x is empty.
  • Fixed bug in TypeVar auto-variance calculations for NamedTuples. Since NamedTuple variables are read-only, they should not cause a TypeVar to be invariant.
  • Added subtyping support or IntEnum and StrEnum members. These literal values are subtypes of the corresponding literal int or str.
  • Fixed bug that results in a false positive error under certain circumstances when passing an overloaded function as an argument to a call.
  • Fixed bug that caused first argument of cast method on memoryview object to be treated as a type expression. Pyright was confusing this method with typing.cast.
  • Fixed a bug that results in incorrect overload matching when one overload contains a zero-arity variant and another overload contains an *args (variadic) parameter.
  • Fixed a bug that results in incorrect type narrowing for truthy/falsy type guards consisting of an Enum member when the enum class derives from ReprEnum. In this case, the "magic" of the enum implementation forwards the __bool__ call to the underlying value.
  • Fixed a bug that results in incorrect type narrowing when using isinstance with an instance of a generic class as the first argument and a concrete subclass as the filter type.
  • Fixed bug in type narrowing logic for value patterns, specifically when two enums with members of the same name are involved.
  • Fixed bug that causes infinite recursion and memory exhaustion under certain circumstances involving recursive type aliases where the type alias is used as a type argument.

Enhancements:

  • Updated typeshed stubs to the latest version.
  • Added support for bool expansion to Literal[True] | Literal[False] during pattern matching when using value patterns.

Behavior Changes:

  • Changed disableLanguageServices feature to apply to hover text as well as other language services. Previously, hover text was excluded.
  • Allow Final and ClassVar to be combined in both directions within a dataclass. Previously, the Final qualifier needed to be the outermost.

Published 1.1.374

31 Jul 04:33
Compare
Choose a tag to compare

Note: This week's release includes some major changes related to TypeVar constraint solving that have been in the works for a while. These changes simplify the code, make constraint solving behaviors more consistent, and eliminate a number of false positive errors that were reported over the past year. However, these code changes produce different constraint solving behaviors in some cases. These extensive code changes also come with the potential of regressions. I've done extensive analysis of the type checking outputs across over a hundred public code bases, but it's possible that I've missed something. Please report any new behavior that you think is a bug.

Bug Fixes:

  • Fixed bug in logic that validates subtyping relationships between TypeIs[T], TypeGuard[T] and bool when used in a return type of a callable.
  • Fixed bug that results in a crash if Optional is used with no subscript (i.e. Optional[]).
  • Fixed bug in isinstance type narrowing if the second argument is object and the first argument is a type instance.
  • Fixed a bug that results in a crash in certain conditions involving a corrupt builtins.pyi stub.
  • Fixed recent regression that results in incorrect isinstance type narrowing when the filter class and the type are both protocols.
  • Fixed bug that results in a warning if the self parameter in an __init__ method is given an explicit Self annotation.
  • Fixed recent regression that results in a false positive error when evaluating certain nested constructor calls when used with bidirectional type inference.
  • Fixed false positive error when iterator returns a class object from its __iter__ method.
  • Fixed recent regression that results in a false positive error under certain circumstances when yield expression includes a call to a constructor.
  • Fixed a bug that results in an incorrect "inconsistent overload" error when the overloads return TypeIs or TypeGuard and the implementation returns bool.
  • Fixed a bug that results in incorrect type narrowing when tuples are used in conjunction with TypeIs.
  • Fixed a bug that can result in incorrect type evaluation when an isinstance type narrowing results in an intersection type.
  • Fixed bug that results in a false negative if a __set__ descriptor method is marked deprecated and is implicitly accessed using an augmented assignment operator, as in a.x += 1.
  • Fixed bug that can result in a false negative when a function return type is a TypeVar and the function falls through and implicitly returns a None.
  • Fixed bug that can result in a false positive when calling the constructor within a class that has unannotated __init__ or __new__ method parameters.
  • Fixed bug that results in false positive error under certain circumstances when solving type variables that involve literal values.
  • Fixed bug that results in a false positive when using a two-argument form of super() outside of a class.

Enhancements:

  • Improved signature help for constructor calls. Replaced old heuristics that displayed either the __init__ or __new__ signature with a mechanism that uses the recently-ratified typing spec algorithm for converting a constructor into a callable. This is prompted in part by this discussion.
  • Added error check for an enum attribute with a "naked" Final attribute. This should be considered invalid.
  • Added a new configuration option enableReachabilityAnalysis. It is off by default when typeCheckingMode is "off" but otherwise on by default. When disabled, it causes pyright not to identify code blocks that are determined to be unreachable via type analysis. Code blocks that are determined to be unreachable via non-type information are still displayed as such.
  • Enhanced type narrowing for sequence patterns to support tuple expansion when the subject is a tuple whose entries are union types.
  • Added missing check for Final variable assigned in a loop.
  • Added support for @deprecated decorator on magic methods for unary and binary operations.
  • Added support for @deprecated on __bool__ magic method used by not operator.
  • Added support for @deprecated on __new__ methods used implicitly during a class constructor call.

Other Changes:

  • Changed evaluation behavior for TypeVar bounds, constraints, and defaults to enforce type expression evaluation rules, consistent with the typing spec.
  • Eliminated error condition when using a subscript expression for a generic class that does not conform to type expression rules (e.g. list[1 + 2]) if the expression is a value expression.
  • Modified heuristics in T is None type narrowing logic to handle TypeVars with no bounds better. The previous logic was arguably correct, but it produced results that were unexpected by some users.
  • Adjusted the heuristics for constraint solving to favor solutions of type T over type[T]` when both are valid.

Published 1.1.373

24 Jul 00:23
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed regression that results in a false positive when an Annotated type is used in a type argument within a specialized type on the LHS of a call expression, such as list[Annotated[int, ""]]().
  • Fixed a bug that results in incorrect type evaluation in certain edge cases involving bidirectional type inference with TypeVarTuples.
  • Fixed a bug that results in a false positive error when using bidirectional type inference for a call expression where the expected type is a union.
  • Added the distinction between "external" versus "internal" type variable scopes. This is important for generic class implementations that call their own constructors.
  • Fixed a bug that results in incorrect type narrowing when using TypeIs form when the return type of the type guard function is a specialized generic class.
  • Fixed bug that results in a false positive "overlapping overload" diagnostic when the later overload includes a callback function with a TypeVar in a parameter type.
  • Fixed bug that resulted in an infinite loop when evaluating a call that passes the same call as an argument. Simplified tracking of unique signatures within the code.
  • Fixed a bug that can cause a hang during type analysis for complex code with loops. There are rare circumstances that can cause types not to converge due to symbol dependencies and unstable overload resolution. This change adds a hard limit on the number of attempts to converge types in a loop before giving up.
  • Fixed a bug that results in false negatives in certain cases involving bidirectional type inference for constructor calls.
  • Fixed issues with the reportInconsistentConstructor. It produced false negatives in some cases and produced bad error messages in other cases.
  • Fixed bug that results in a crash if an explicit specialization of a class parameterized by a ParamSpec has zero type arguments. This is a syntax error, but it shouldn't cause the type evaluator to crash.

Behavior Changes:

  • Changed all diagnostic generated in the type evaluator to have a diagnostic rule associated with them so their severity is under user control.
  • Changed internal behavior to retain type alias information when applying solved type variables for a type. This doesn't change type checking behaviors, but it changes language server output (e.g. hover text) in some cases. It can also affect diagnostic messages.

Enhancements:

  • Added provisional support for draft PEP 736 (keyword argument shortcut syntax).
  • Added check for class attribute type declarations that use method-bound type variables. These should be illegal.
  • Improved type evaluation for tuples index expressions with negative subscripts and an entry with an indeterminate length.
  • Made support for "converter" parameter in dataclass_transform fields non-experimental. This functionality has been approved by the typing council.
  • Added support for bidirectional type inference for __extra_types__ in a closed TypedDict.
  • Updated typeshed stubs to the latest version.
  • Added support for auto-synthesized __replace__ method in dataclass and namedtuple classes, a new feature in Python 3.13.

Published 1.1.372

17 Jul 02:15
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that can result in incorrect evaluation of a traditional (pre-PEP 695) type alias the defines a union which is later used as the second argument to an isinstance or issubclass call.
  • Fixed bug in type narrowing logic for sequence pattern matching when a "star" entry in the pattern captures a TypeVarTuple. The resulting type should be Unknown rather than the unpacked TypeVarTuple.
  • (from pylance) Fixed regression that broke CLI when used with poetry or other tools that depend on the working directory.
  • Fixed a recent regression that results in a false positive when the fully-qualified form of typing.Request is used in an annotation expression.
  • Fixed a bug that results in false positive reportInconsistentConstructor errors if one or both of __init__ or __new__ are overloaded.
  • Fixed a bug that results in a false positive reportOverlappingOverload error in certain cases involving ParamSpec and Concatenate.
  • Fixed a bug that results in incorrect import resolution behaviors when a ".py" file and a directory have the same name, and the directory doesn't have a __init__.py file in it. In this case, the ".py" file should take precedence during imports.
  • Fixed inconsistent behavior when evaluating a binary expression with an or or and operator when the LHS evaluates to a literal int, str, bytes or bool type.
  • Fixed bug that results in a false positive error under certain circumstances when a generator function with no type annotation contains a return value.
  • Fixed bug that results in some circumstances in incorrect specialization of type[T] when T evaluates to Any.
  • Fixed false positive error when using an overloaded __init_subclass__ method under certain circumstances.

Enhancements:

  • Added support for negative type narrowing (in the fall-through case) for a mapping pattern consisting of a single dictionary expand entry. This should match all mapping types, eliminating them in the fall-through case.
  • Added support for class declarations within an enum class body -- both with and without @member and @nonmember decorators.
  • Added "literal math" support for bitwise operators (left shift, right shift, logical or, logical and, logical xor, and invert).
  • Improved the handling of bidirectional type inference for call expressions when the expected type comprises a union.
  • Added "literal math" support for exponentiation operator.
  • Improved performance of type analyzer an average of 12% by refactoring internal data structures and making key objects "monomorphic". This allows the V8 Javascript engine (used in node) to JIT more optimal code.

Behavior Changes:

  • Changed union creation logic to retain (rather than elide) redundant literals in some cases. In particular, for type expressions that explicitly include literals along with their non-literal counterpart like Literal[1] | int. Retaining these redundant subtypes can be useful for language server features like completion suggestions.
  • Changed the type of the __doc__ attribute for a module to always be str | None. Previously, pyright changed its declared type to str if a docstring was present in the module, but this is incorrect because it's a writable value and can be set to None.
  • Changed logic for explicit specialization to allow Never as a type argument for a value-constrained type parameter if Never is an explicit constraint.

Published 1.1.371

09 Jul 23:07
ed49da5
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed regression that results in a false positive when a traditional type alias (not using PEP 695 syntax) defines a union and is then used as a second argument to an isinstance or issubclass call.
  • Fixed bug that results in a false positive error when an unpack operator is used in an unparenthesized tuple expression on the RHS of an augmented assignment operator on Python 3.9 and newer.
  • Fixed bug that results in a false positive error when using a TypeVar with an upper bound of type as a base class in a class statement.
  • Fixed bug that results in false negative when a list or set expression includes more than 64 elements and is being evaluated with a bidirectional inference context.
  • Fixed type evaluation of old-style (pre-PEP 695) type alias that aliases a generic class when it is used as a direct constructor call.
  • Fixed bug that causes a false positive error when an __init_subclass__ has overloads.
  • Bumped minimum engine version from 1.86 to 1.89 to match the recently-updated language client library requirements.

Behavior Changes:

  • Changed the hard-coded type of the __class__ symbol to be Self@T rather than T (where T is the enclosing class).

Enhancements:

  • Added experimental support for multithreaded type checking in CLI. You can now specify --threads followed by an optional thread count. If no count is specified, pyright will use a value equal to the number of logical processors. Experimentation shows that this can speed up type checking by 2x to 3x for larger code bases. It has little or no effect (and possibly negative effects) for small code bases.
  • Improved detection of the use of variables used in type annotations.
  • Improved type narrowing in the fall-through case for sequence patterns when the pattern includes a star pattern and the subject type is a tuple with an indeterminate entry.
  • Improved handling of tuple expressions used in type expressions that involve specialization, such as dict[()].
  • Updated typeshed stubs to the latest version.
  • (From pylance) Improved security of python interpreter execution when determining the default python import resolution paths and python version.

Published 1.1.370

02 Jul 23:55
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that resulted in a false negative when assigning to type tuple[Never].
  • Fixed bug that results in incorrect type isinstance or issubclass type narrowing when using a type variable with an upper bound that includes a promotion type.
  • Fixed recent regression that results in an assertion failure (and therefore a crash) when type() is called with dynamic base classes.
  • Fixed bug that results in a false positive when a protocol includes a method implementation that conditionally raises NotImplementedError.
  • Fixed bug that results in false positive reportInconsistentOverload and reportNoOverloadImplementation errors when an overloaded decorator is applied to a non-overloaded function or method.
  • Fixed recent regression that results in false positive when a inner function with an inferred return type is a coroutine (async) and is referenced within the function body in which it's declared.
  • (from Pylance) Fixed recent regression that results in diagnosticSeverityOverrides to be ignored if a pyproject.toml file is present, even if there is no [tools.pyright] section in it.
  • Fixed bug that results in incorrect type evaluation of a function that accepts a Callable[P, T] and is passed a class object whose constructor needs to be converted to a callable.
  • Fixed bug that results in a spurious error when evaluating a quoted (forward reference) type expression that includes an index expression within a TypeAlias definition.
  • Fixed a bug in the type narrowing for the "x is " type guard pattern when <class> is a specific class T, as opposed to a variable of type type[T].
  • Fixed bug that resulted in a false positive error when an abstract class is used for a NewType and the new type is constructed.
  • Fixed bug that results in the incorrect default value of a variadic type variable when the type argument is not provided. It should default to *tuple[Any, ...], not *tuple[Any].
  • Fixed bug that results in a false negative when passing an extra keyword argument to a callable that is parameterized with a ParamSpec.
  • Fixed bug that results in a false positive reportUntypedFunctionDecorator error under certain circumstances.

Enhancements:

  • Updated typeshed stubs to the latest version.
  • Improved analysis performance for complex code flow graphs by adding a cache for reachability.
  • Implemented optimization in the protocol matching cache.
  • Improved handling of special forms, including TypeAliasType instances, when used in value expressions.

Published 1.1.369

25 Jun 16:10
Compare
Choose a tag to compare

Behavior Changes:

  • Improved consistency of unreachable code. Previously, unreachable code was not supported for if or else suites when the condition type was narrowed to Never.
  • Changed hover provider output for type aliases to conform more closely with the new Python 3.12 type syntax.

Enhancements:

  • Added support for detecting mismatched property types in base classes used for multiple inheritance.
  • Improved reportUninitializedInstanceVariable check to handle dataclass variables that are initialized implicitly by the synthesized __init__ method.
  • Added support for walrus (assignment) operator within set literal expressions if the python version is >= 3.10. The grammar was changed in 3.10 to support this.

Bug Fixes:

  • Fixed recent regression in reportUninitializedInstanceVariable check relating to NamedTuple instance variables.
  • Fixed bug that leads to a false negative when a subscript object used in an index expression supports __index__ but the indexed object specifies that it requires int.
  • Fixed recent regression that results in a runtime assert (and therefore a crash) in certain circumstances when computing the MRO for a class.
  • Fixed bug that results in an incorrect overload implementation diagnostic when using tuple[()] in overloads.
  • Improved diagnostic messages for type errors detected during __set__ and __delete__ calls to a descriptor object.
  • Fixed bug that results in a false positive error when using a callback protocol with a function-scoped type variable.
  • Fixed bug that incorrectly evaluates a constructor call to a constructor that infers a class-scoped ParamSpec when the passed function is generic.
  • Fixed bug that leads to a spurious "unbound variable" diagnostic when a variable is assigned a value using a walrus operator and is later used in a ** call argument.
  • Fixed bug that results in incorrect type narrowing in the negative (fall-through) case of a match expression when the subject expression is an unbounded tuple.

Published 1.1.368

18 Jun 22:08
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that causes warnings.deprecated not to work if the python version is 3.13. This was caused by recent changes to typeshed stubs.
  • Fixed bug that results in inconsistent diagnostics when surrounding an argument expression with parentheses.
  • Fixed bug that causes a "bare" type (with no type argument) or type[Any] to be treated as a possible descriptor object.
  • Fixed regression that results in an internal assertion (and crash) related to TypeVar variance inference.
  • Fixed a bug in the "type printer" (the component responsible for translating a type into its textual form) for type aliases defined using PEP 695 syntax.
  • Fixed bug that resulted in the incorrect synthesis of __dataclass_fields__ for named tuples.
  • (Contributed by @insync) Fixed stubPath's default value in configuration schema.
  • Fixed bug in pattern matching for Callable() in the negative (fall-through) case.
  • Fixed bug that results in unions consisting of different specialized forms of a generic TypedDict to "lose" all but one of these subtypes.

Behavior Changes:

  • Changed inference behavior for generator functions with no reachable yield or yield from statements. The "yield type" (the first type argument to Generator) is now inferred as Never in this case rather than None.
  • Changed the behavior of double underscored symbols that are part of a module's namespace when that module is not a stub or in a "py.typed" package. Such symbols are no longer ignored, although they are considered private.
  • Changed the way that PEP 695 type aliases are displayed when hovering over a reference to the type alias. Previously, the symbol was displayed as TypeAliasType rather than the expanded type alias type.

Enhancements:

  • Added support for deprecated objects that are instantiated prior to being used as a decorator. This allows for a factory usage pattern.
  • Added check for illegal use of Protocol type argument that is not a type parameter. The runtime generates an exception for this condition.

Published 1.1.367

12 Jun 02:49
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in incorrect truthy/falsy type narrowing for an enum that overrides __bool__.
  • Fixed bug that results in a false positive when accessing a generic attribute in a base class from a subclass that explicitly specializes the generic type.
  • Fixed bug that results in duplicate and (contradictory) diagnostic outputs in certain cases where reveal_type is used in a loop.
  • Fixed a bug that results in incorrect (local) type evaluation of an instance variable with a declared type when assigned within a loop that uses an augmented assignment.
  • Fixed bug that causes Final annotation not to be honored when wrapped in an Annotated annotation.
  • Fixed bug that results in a false positive error under certain circumstances involving tuple type narrowing in a loop.
  • Fixed bug that led to divergent behaviors between pyrightconfig.json and pyproject.toml configurations. Specifically, default exclude patterns were not added in the case of pyproject.toml. Thanks to @augustelalande for contributing to this fix.
  • Fixed bug that results in parameter types being converted to Any when converting a NewType or dataclass constructor to a callable.

Enhancements:

  • Updated typeshed stubs to the latest version.
  • Implemented provisional support for PEP 746, which provides consistency checks for metadata used in an Annotated annotation.
  • Added check for except* to enforce that exception class does not derive from BaseExceptionGroup.
  • Added the ability to override type checking configuration settings for each execution environment. This allows, for example, a test directory to use different settings than the directories that contain production code.

Behavior Changes:

  • Added extra blank line to JSON output to assist with parsing when used in watch mode.
  • Changed the import resolution order to better reflect runtime behavior and match a proposed change to the typing spec. In particular, stdlib typeshed stubs are now resolved prior to site_packages.

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.