Skip to content

Releases: microsoft/pyright

Published 1.1.383

01 Oct 22:57
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that resulted in an incorrect error when using a # pyright: standard directive.
  • Fixed a bug that leads to incorrect type evaluation when "literal math" for unary operators are applied to a TypeVar value that has a literal value upper bound.
  • Fixed bug with the provisional TypeForm support that breaks aliases of Annotated.
  • Fixed bug that results in incorrect variance inference for some generic type aliases that use auto variance and nested callable types.
  • Fixed bug that resulted in a false negative when assigning a specialized recursive generic type alias to itself when variance of its type parameters are not covariant.
  • Fixed several bugs related to the explicit specialization of a generic type alias parameterized by a single ParamSpec. Concatenate was being handled incorrectly.
  • Fixed bug that results in a false negative when a type variable is defined with the expression .... This should be flagged as an illegal type expression.
  • Fixed bug that caused type alias to Never or NoReturn to lose its type alias association in some circumstances.

Enhancements:

  • Improved verbose logging of execution environment information.
  • Added code to propagate information about certain typing module imports from an implicitly-imported module (e.g. builtins or __builtins__.pyi) so Final and ClassVar can be treated as special forms by the binder. This fixes the use of these typing symbols in notebooks within pylance, which leverages implicitly-imported modules to "chain together" notebook cells.
  • Added check for use of a TypedDict class within a case statement class pattern. This condition generates a runtime error.
  • Improved type evaluation performance in certain cases involving protocol matching for complex, nested protocols.

Published 1.1.382

25 Sep 00:59
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that can result in incorrect type evaluation behaviors if a call to type is used within a loop.
  • Fixed bug that results in incorrect type inference for list, set, dict, and tuple expressions that include modules in them.
  • Fixed bug that results in false positive error when using a Final variable in a protocol and a NamedTuple or frozen dataclass as a concrete class.
  • Fixed bug that results in a false negative when assigning a value to a union type that includes the same type variable multiple times in at least one invariant context. This change eliminates the concept of a "locked" constraint tracker, which is no longer needed and was the underlying cause of the bug.
  • Fixed bug that resulted in a "reportIncompatibleMethodOverride" error being reported in the wrong location when a property method has a decorator applied to it.
  • Fixed a bug that results in a false positive when assigning Never to a type variable in a contravariant context.
  • Added check for the illegal use of TypeForm as the second argument to an isinstance or issubclass call.
  • Fixed bug that results in incorrect type narrowing when a value typed as TypeForm is used as the first argument to isinstance.
  • Fixed a bug that can result in a false positive error when a function signature contains a positional-only parameter and a keyword parameter with the same name. This can result from the application of a ParamSpec or through the use of an unpacked TypedDict.
  • Fixed a bug that results in incorrect type evaluation behaviors when a class has a custom metaclass with a __call__ method and a __new__ or __init__ method that provides a different bidirectional type inference context for parameters.

Enhancements:

  • Added special-case handling for the len(t) == L type guard pattern to handle the negative narrowing case where tuple t has a minimum length of L. In this case, the narrowed type can be computed whereas previously it was left unnarrowed.
  • Improved hover text for converters in dataclass-like classes.
  • Updated typeshed stubs to the latest version.
  • Extended reportUnnecessaryComparison to cover more cases involving is and is not operators.

Published 1.1.381

17 Sep 23:14
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in incorrect type narrowing for sequence patterns in the negative (fall-through) case when the subject is a tuple with an unbounded entry.
  • Fixed recent regression that results in a false positive error when attempting to assign the expression type(Any) to type type[Any].
  • Fixed a bug that results in incorrect evaluation of a variable in a doubly-nested loop that is assigned a value in an assignment expression.
  • Fixed a bug that results in incorrect narrowing of types for TypeIs user-defined type guard in certain cases when variable type is a union.
  • [Contribution by @dcolascione] Fixed bug that results in a condition where imports stop resolving after file edits that change the set of modules that a file imports.
  • Fixed recent regression that results in incorrect type narrowing for isinstance in the negative case when using type as a filter.
  • Fixed bug that results in incorrect reporting of the Python version in a deprecation diagnostic message.
  • Fixed bug that results in incorrect code flow involving a call to a NoReturn callable with a function decorator applied.
  • Fixed bug that results in a spurious "symbol refers to itself" error under very specific conditions.
  • Fixed bug that can theoretically result in spurious errors when evaluating expressions that involve parameter symbols.
  • Fixed bug that results in incorrect type narrowing when TypeIs intersects type[A] with type[B]. Previously, pyright was producing <subclass of type[A] and type[B]> but now produces type[<subclass of A and B>].
  • [From pylance] Fixed recent regression that caused venvPath specified in language server settings to be ignored.
  • Fixed bug that results in a confusing error message extension referencing a missing __set__ method when assigning to a class variable that is not a descriptor object.
  • Fixed a bug that results in a false positive type error and confusing error message when assigning to a class variable that uses Self in its type definition.
  • Fixed a bug that results in spurious "variable not allowed in type expression" errors when a type alias is used in a loop in both a type expression and a value expression.

Behavior Changes:

  • Updated provisional support for TypeForm based on feedback to draft PEP 747.

Enhancements:

  • Expanded reportUnnecessaryIsinstance check to report cases where an isinstance or issubclass call always evaluates to False.
  • Improved error message for type violation in assignment statement where the LHS is an instance variable reference.
  • [From pylance] Update Unicode range tables to match Unicode 16.0, which is used for Python 3.14.

Published 1.1.380

10 Sep 21:56
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a recent regression that results in incorrect type evaluation when using a two-argument form of super() and the second argument is type[Self].
  • Fixed a recent regression that results in a false positive type error when converting certain constructors (such as for the class defaultdict) to a callable type.
  • Fixed recent regression that results in a false positive under certain specific circumstances involving higher-order functions that return generic callable types.
  • Fixed a bug that results in a false positive error during protocol matching because writable class variables defined in a named tuple or a frozen dataclass were considered read-only.
  • Fixed a bug that causes incorrect type narrowing of expressions used within a tuple expression in the subject expression of a match statement.
  • Fixed a bug that results in an incorrect type evaluation of a higher-order function that is passed an overloaded function.
  • Fixed recent regression that results in a false positive error under very specific circumstances involving a function with a TypeVar used in both a contravariant and covariant context and combined by union with other types in the contravariant context.
  • Fixed a bug that leads to a false positive "default value is specified as ..." when using --verifytypes and the function has a decorator applied that uses a ParamSpec.
  • Simplified check for unnecessary isinstance call. Removed a bunch of redundant code and fixed a number of bugs in the process.
  • Fixed a bug that leads to incorrect type narrowing with isinstance or TypeIs when the filter type (the second argument to isinstance) is a subclass of type.
  • Fixed bug that results in incorrect type narrowing for the in (containment) operator when the filter includes class objects (instances of type).
  • Fixed a bug that results in incorrect type narrowing for the x is ... (ellipsis) type guard pattern.
  • Fixed a bug in the stub generator so it properly outputs type aliases that use the PEP 613 TypeAlias qualifier.
  • Fixed bug that causes a crash in the language server under certain circumstances with partially-written code that has syntax errors.
  • Fixed a bug that results in incorrect type narrowing for TypeIs when it is used with a Callable type form.
  • Fixed several inconsistencies and bugs in the isinstance type narrowing code involving callables

Enhancements:

  • Added performance optimization to better handle the case where a tuple expression contains thousands of entries. This is not typically found in hand-written code, but it can appear in computer-generated code.
  • Added support for custom metaclasses that derive from ABCMeta. Classes instantiated from such metaclasses are now treated as abstract.
  • Updated typeshed stubs to the latest version.

Behavior Changes:

  • Changed the behavior of the dictionary expansion operator (**) when used in an argument expression for a call and the operand is a TypedDict. It now takes into account the fact that a (non-closed) TypedDict can contain additional keys with object values. This new behavior is consistent with mypy.
  • Removed support for python-2 raise statements with comma-delimited operands.
  • Changed behavior of raise evaluation logic to allow type of exception to be Never.
  • Changed behavior to allow a value with type _AnnotatedAlias to be used with an implicit __getitem__ call even though this type is not documented or declared in typeshed.
  • Changed stub generator to avoid emitting a from __future__ import statement, which has no meaning in stub files.
  • Removed support for custom callable type guard pattern. Now that typeshed defines this with a TypeIs, we no longer require custom logic here.

Published 1.1.379

04 Sep 00:04
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that results in confusing hover information for an attrs field that uses a converter.
  • Fixed bug that results in incorrect type evaluation when assigning a recursive type alias to a tuple or list.
  • Fixed a bug that can result in difficult-to-reproduce type evaluation errors when modifying code in your editor and using pyright as a language server.
  • Fixed bug that results in the incorrect type when the Callable special form is used in a value expression.

Enhancements:

  • Added check for concatenated bytes and str literals.
  • Added provisional support for draft PEP 747 and the TypeForm special form.
  • Updated some diagnostic strings to refer to "type expression" rather than "type annotation" since they apply to some cases that don't involve annotations.

Published 1.1.378

28 Aug 03:53
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in incorrect logging of the pythonVersion string.
  • (from Pylance) Fixed issue that resulted in the incorrect pythonVersion when a pyproject.toml is present with a "[tool.pyright]" section.
  • Fixed a bug that results in false negatives for errors in argument expressions used in a call to functools.partial in some cases. This same issue also causes symbols accessed in these arg expressions to not be marked as referenced.
  • Fixed bug that results in a crash in very specific circumstances that involve binding a method parameterized by a function-scoped ParamSpec.
  • Fixed a bug that resulted in incorrect evaluation when converting a constructor to a callable and the constructed class has a metaclass with a __call__ method whose cls parameter is annotated with type[T].
  • Fixed bug that results in a reportIncompatibleMethodOverride diagnostic being reported in the wrong location in some cases involving decorators.
  • Fixed a bug that results in a false negative when overloads overlap due to default values.

Behavior Changes:

  • Changed the default value of the disableBytesTypePromotions setting from false to true. It has been over two years since PEP 688 was accepted, so it's time for us to stop treating bytes as an alias for bytes | bytearray | memoryview. This is a breaking change and may require an update to the pyright configuration for some code bases.

Published 1.1.377

21 Aug 02:02
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a crash under certain circumstances when a ParamSpec without a scope is used illegally to specialize a class.
  • Fixed a bug that results in a false positive error when assigning a TypeGuard[T] or TypeIs[T] to a supertype of bool (like int).
  • Fixed a bug that leads to a crash when --pythonversion and --threads CLI options are used together.
  • Fixed a bug that leads to incorrect type evaluation in certain specific conditions involving a function decorator with an return type inferred from an inner function parameterized by a ParamSpec.
  • Fixed bug that results in a false positive error under very specific conditions involving a recursive type alias that is defined in terms of another type alias.

Enhancements:

  • Changed type checking logic to retain a reference to default expressions in function signatures, including synthesized signatures (such as __init__ methods in dataclasses). This allows the original default value expression to be printed in error messages and language server strings.
  • Updated typeshed stubs to the latest version.
  • Added unreachable code reporting for case statements that are never matched based on type analysis.

Published 1.1.376

14 Aug 00:11
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a crash when an empty tuple is used to specialize a generic type alias parameterized by a ParamSpec.
  • Fixed a bug that results in a false positive reportInconsistentOverload error when the implementation of the overload includes a decorator that changes the type of the implementation to a non-function type.
  • Fixed bug that results in a false positive error when type argument for Literal doesn't follow type expression rules within a value expression context.
  • Fixed regression that resulted in a hang when determining whether an overload implementation with generics was compatible with its overloads.
  • Fixed bug that results in a false negative reportIncompatibleMethodOverride when the child class method uses a type parameter that is scoped to the child class.
  • Fixed bug that produces signatures with extra (unnecessary) positional-only and keyword-only separators when using a TypedDict with zero fields.
  • Improved consistency of parameter name restrictions for the reportSelfClsParameterName check. Previously, different rules were applied to __new__ and class methods within metaclasses.
  • Fixed a false positive error when solving type variables in a call that involves a lambda.
  • Fixed bug that results in a confusing type in an error message when isinstance type narrowing between a type and another type creates a subclass.
  • Fixed bug that leads to false positive error when a protocol has a read-only property a class has a Final variable.
  • Fixed bug that leads to a hang under certain circumstances involving deeply-nested higher-order functions.
  • Fixed bug that results in a confusing type in an error message when isinstance type narrowing between a type and another type creates a subclass.

Enhancements:

  • Enhanced argument-to-parameter matching logic to support dictionary unpacking where the dict key type is a union of literals.

Behavior Changes:

  • Changed composition of settings that affect type checking behaviors. Previously, some LSP settings that affect type checking could override config files. Now, the config file always "wins". Command-line parameters passed to the CLI version of pyright win over both LSP settings and config files.
  • Changed synthesized comparison methods (__lt__, etc.) for dataclasses when order=True to use Self rather than an instance of the class. This is not only more consistent with other synthesized methods, but it also preserves covariance of type variables if the dataclass is frozen.
  • Changed behavior for protocols that have methods with method-scoped type variables. These are no longer treated as free type variables during protocol matching, so they can be used to support rank-2 polymorphism. This behavior is not currently dictated by the typing spec, but it is more consistent with mypy.

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.