Skip to content

Releases: microsoft/pyright

Published 1.1.398

26 Mar 03:43

Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a spurious type error when a ParamSpec is used in conjunction with a dataclass and a contextmanager.
  • Fixed recent regression that results in a false negative when calling a function with a positional-only parameter whose type is generic and has a concrete default argument value.
  • Fixed regression that results in an Unknown type evaluation where previously Any was generated during bidirectional type inference.
  • Fixed bug that results in incorrect overload resolution when an unpacked argument is of unknown length and potentially matches multiple overloads.
  • Fixed bug that results in a variable being displayed as "not accessed" if it's used in an argument expression for a call expression whose base type is a module or None.
  • Fixed bug that results in a hang under certain very specific circumstances involving a protocol method that has been decorated in such a way that it can no longer be bound to the owning protocol class.
  • Fixed a bug that contributes to inconsistent type evaluation results when using the "--threads" feature.
  • Fixed bug that results in incorrect "literal math" result when dividing Literal[0] by a negative literal int value.
  • Fixed a bug in "literal math" for shift operators. If the RHS value is negative, the operation is invalid, so literal math shouldn't be applied.
  • Fixed bug in "literal math" logic for modulo and floor divide operators that affect cases where operands have different signs.

Behavior Changes:

  • Changed algorithm for applying type narrowing upon assignment when one or both of the declared type or assigned type contain "Any".
  • Removed special-casing for async functions that skips check for implicit return when the return type is NoReturn.

Enhancements:

  • Updated typeshed stubs to the latest version.
  • Extended reportPrivateImportUsage to report the use of symbols imported from private submodules in a "py.typed" or stub library.
  • Extended the reportUnnecessaryComparision check to support the patterns x is None and x is not None in cases where x is provably disjoint in type.
  • Added generalized support for assignment expressions (walrus operators) for type guards.
  • Extended the type narrowing logic for the x == L type guard pattern so it supports the case where x is LiteralString and L is a string literal.

Published 1.1.397

19 Mar 18:57

Choose a tag to compare

Bug Fixes:

  • [From pylance] Fix problem with partial stub service not being part of Pyright CLI.
  • Added additional special-casing to x in y type guard logic to handle LiteralString values.
  • Partially eliminated inconsistent error reporting when calling a function with a default argument that is not assignable to the declared parameter type. An error will still be reported in the case where the declared parameter type includes an unsolved type variable in most cases, but it will no longer be reported if the unsolved type variable is due to a pseudo-generic class.
  • Fixed bug that results in an identifier being marked "unaccessed" if it is used in an argument expression to a call whose type is possibly unbound.
  • Fixed bug that leads to a false negative when evaluating a call expression where the callable type is Any and an argument expression uses dictionary unpacking but the operands type is not a mapping.
  • Fixed a bug that results in an incorrect "Unknown" type evaluation under certain circumstances involving an assignment to an annotated variable within a loop.
  • Fixed bug that results in incorrect bidirectional type inference when using nested constructor calls for dataclasses.
  • Fixed a bug that results in incorrect "literal math" results when using a floor divide // operator with literal operands whose signs differ.
  • Fixed a bug that results in a hang under certain circumstances when inferring the return type of a recursive function.

Enhancements:

  • Changed type evaluator to make a best effort to evaluate the return type of a function call even if arguments are missing.
  • [From pylance] Implement support for pull diagnostics in pyright.
  • Added code to enforce that an argument in a call expression that is unpacked is iterable.
  • Improved support for unused import detection for import statements that target multi-part names.

Behavior Changes:

  • Changed the type of __path__ from Iterable[str] to MutableSequence[str]. Both are correct, but the latter is more precise.
  • Improved determinism of --threads diagnostic output by always sorting output by file path.
  • Improved reproducibility of CLI diagnostics in non-threaded case by sorting output by file path.

Published 1.1.396

28 Feb 21:25

Choose a tag to compare

This is a hot fix release that addresses a regression introduced in 1.1.395 that affected several popular libraries including pandas.

Bug Fixes:

  • Reverted previous bug fix that caused errors to be detected and reported in cases where a library defines a function or method with one or more typed parameters with default arguments whose types are incompatible with the parameter type. Previously, pyright reported these errors in some cases but not in others. The bug fix caused these errors to be consistently reported. However, an unexpected number of libraries are impacted by this change. This reversion will give us time to better understand the extend of the issue and determine the correct long-term solution.

Enhancements:

  • Added bidirectional type inference for container types that are parameterized by a protocol that matches a module.

Published 1.1.395

25 Feb 23:41

Choose a tag to compare

Bug Fixes:

  • Fixed a bug that results in noncompliance with the typing spec when a __new__ method has an explicit Any return type annotation. In this case, type checkers should assume that the return type of __new__ is not a subtype of the containing class and should therefore ignore the __init__ method.
  • Fixed bug that results in a spurious "overlapping overload" error if the second both overloads have an *args but the first has one or more additional positional parameters
  • Fixed bug that leads to inconsistent behavior in certain cases involving the evaluation of a call whose target signature involves a parameter with a default argument value, notably where the type of the default value isn't assignable to the declared type of its parameter.
  • Fixed a bug that results in a spurious reportUnknownArgumentType error under certain circumstances.
  • Fixed a bug that resulted in a spurious error under certain specific conditions involving a call to a function or method that doesn't have a return type and whose inferred return type is based on variables calculated in a loop.
  • Fixed a bug that results in an incorrect error when determining assignability of a function with an *args that is unpacked using a *tuple[].
  • Fixed bug that results in a spurious error when an isinstance or issubclass type guard results in a narrowed type that is synthesized as a subclass of type and some other class.
  • Fixed a bug that results in a spurious error when an unpacked iterable argument expression supplies the objects for an *args parameter that is annotated with an unpacked TypeVarTuple.

Behavior Changes:

  • Exempted __init__ from override checks even in the case when the override is an object (such as a context manager) rather than a function.
  • Added special-case logic to permit type[T] to be treated as assignable to TypeForm[T] in accordance with the latest draft of PEP 747.
  • Changed the interpretation of an async function with an empty body (no yield statement) in a stub file or protocol definition that has a return type annotation of AsyncGenerator. Previously, this was assumed to be a generator even though a yield statement wasn't present. It is now assumed to be a Coroutine. This behavior is not spelled out in the typing spec, but pyright's new behavior is now consistent with mypy's.

Enhancements:

  • Improved error reporting for PEP 728 features when enableExperimentalFeatures is not true.
  • Added error check for member access expressions that attempt to bind an instance or class method to an object or class when the method accepts no "self" or "cls" parameter.
  • Added check for invalid creation of TypeAliasType outside of a class or module scope.
  • Updated typeshed stubs to the latest version.
  • Added special-case logic to allow Any to be defined in typing.pyi using a class statement rather than how it has traditionally been defined.

Published 1.1.394

12 Feb 05:31

Choose a tag to compare

Enhancements:

  • Added missing check for a PEP 695 type parameter being the target of a nonlocal statement. This results in a runtime exception, so it should be reported as an error.
  • Improved error message for TypedDict base classes that are not closed but specify an extra_items. Also added check for cases where closed and extra_items are both specified.
  • Updated typeshed stubs to the latest version.
  • Added missing check for the override of a property that is marked @final.
  • Added support for tracking multiple constraint sets when performing protocol matching. This allows protocols with overloaded methods to contribute independent constraint sets.

Bug Fixes:

  • Fixed a bug that results in incorrect handling (and spurious errors) when accessing an attribute on a TypedDict that is shadowed by a TypedDict item.
  • Fixed a spec conformance issue relating to callable assignability when the dest type uses an unpacked TypedDict and the source does not accept **kwargs. The typing spec indicates that this should fail because TypedDicts are not closed.
  • Fixed bug that results in incorrect inferred type for an instance or class variable assigned a value as part of a tuple expression target with an unpack operator (e.g. a, *self.b = (1, 2, 3)).
  • Fixed bug that resulted in incorrect type inference for unannotated variables (either local or class-scoped) that are the target of an augmented assignment.
  • Fixed a bug that leads to a false negative when checking for partially overlapping overloads that have keyword parameters with default argument values.
  • Fixed a bug that causes a false positive "no overload implementation" error when a non-overloaded function uses a decorator that changes its type to a an overloaded function.
  • Fixed bug that results in false negative when a format string with a single quote has a newline character within it. This results in a syntax error at runtime.
  • Fixed regression that resulted in a false positive error when evaluating a call expression that targets an overloaded method and one of the arguments is an enum with more than 64 members.
  • Fixed a bug that results in a false positive "overlapping overload" error under certain circumstances involving recursive types.
  • Fixed a bug that results in a false positive error when assigning a tuple of indeterminate length to a zero-length tuple target.
  • Fixed a bug that leads to incorrect (unsound) type narrowing when using the x in y type guard pattern. The in operator uses equality checks, and __eq__ can succeed for objects of disjoint types, which means disjointedness cannot be used as the basis for narrowing here. This change also affects the reportUnnecessaryContains check, which leverages the same logic.
  • Fixed recent regression that affected the evaluation of calls that target certain overloads that include an *args parameter in the fallback (the last overload). In particular, this affected the zip constructor.
  • Removed errant check for @final consistency when it is applied to TypedDict.
  • Fixed a bug that results in incomplete renames when renaming a class or function that uses PEP 695 type parameter syntax.

Behavior Changes:

  • Changed behavior of TypedDict to synthesize a fall-back overload for the pop method to handle the case where the caller passes a key name that is not specified in the TypedDict definition.
  • Changed the type of an async def function from typing.Coroutine to types.CoroutineType for improved type accuracy.
  • Exempted __slots__ symbol when determining whether a class is a callback protocol.

Published 1.1.393

29 Jan 03:41

Choose a tag to compare

Bug Fixes:

  • Changed the fallback type from Unbound to Unknown for the case where pyright determines that a symbol requires code flow analysis but the execution scope exceeds the cyclomatic complexity threshold.
  • Fixed a bug that results in a false positive "recursive type definition" error under certain circumstances when the number of declarations for a symbol exceeds the internal threshold of 16.
  • Fixed a bug that results in incorrect handling of a "bare" ClassVar annotation either with or without an assignment.
  • [From pylance] The default python version was not being picked up from the environment.
  • Fixed bug that results in false negative when a parameter is used within a type expression and the parameter's type is a TypeVar or Self.
  • Fixed bug that results in a false negative when two import statements shadow the same symbol and an attribute is accessed between the two import statements.
  • Fixed bug that results in a crash (due to infinite recursion) if an enum class uses a reference to an enum member in an annotation for that same enum member.
  • Fixed a bug that results in incorrect type evaluation when passing a function with a callable parameter that uses Concatenate plus ParamSpec to a function that accepts a callable with just a ParamSpec.
  • Added missing check for illegal use of Final within a TypedDict or NamedTuple definition.
  • Tweaked the algorithm for computing the complexity of a code flow graph to accommodate slightly larger graphs before giving up.

Enhancements:

  • Updated typeshed stubs to the latest version.
  • Added @override enforcement for an overloaded method that has no implementation.
  • Added code to conform with the new checks mandated in the typing spec for @final and @override applied to an overload.
  • Extended type narrowing for the X is L and X is not L type guard pattern. Previously, narrowing was performed only when L was an enum or bool literal. Narrowing is also now applied for other literal types but only in the positive (if) direction.
  • Modified the overload call evaluation logic to conform with the new proposed type specification rules regarding *args parameters.
  • Added support for argument type expansion of bool, enums, and tuples of fixed length when evaluating overloads. This behavior is mandated by the new draft typing spec update.

Published 1.1.392

15 Jan 06:18

Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in incorrect evaluation when passing a callable with a "*args" parameter to a callable with a Concatenate and ParamSpec.
  • Fixed bug that results in the extraPaths configuration option within an execution extending rather than overriding the extraPaths provided in the top-level config.
  • Fixed bug in dictionary expression type inference that results in the incorrect type when a dictionary expansion is used and the resulting expansion type is unknown.
  • Improved handling of __getitem__, __setitem__ and __delitem__ magic method modeling to handle descriptor objects.
  • Eliminated type evaluation order dependency that results from return type inference that involves recursion.
  • Fixed bug that results in an incorrect "overlapping overload" error message in certain cases involving parameters annotated with Self.
  • Fixed bug that results in a spurious error when an assignment expression (walrus operator) is used as an argument to a constructor call when the constructor has both a __new__ and __init__ with differing bidirectional type inference contexts.
  • Fixed bug that results in a spurious "incompatible method override" error when two subclasses with an overloaded method are combined using multiple inheritance.
  • Fixed bug that results in an "incompatible method override" false negative when overriding a method that uses class-scoped type parameters with a method that uses method-scoped type parameters.

Behavior Changes:

  • Changed error messages to refer to lowercase list, dict and type rather than their deprecated uppercase counterparts now that Python 3.8 is EOL'ed.
  • Improved type narrowing for issubclass in the negative ("else") case when the subject type is type or Any.

Enhancements:

  • Added missing syntax error check for positional argument that follows an unpacked keyword argument in a call expression. Also added a check for an unpack operator used within the first argument of a cast call.
  • Changed code that computes unescaped literal string type to convert CRLF to LF within multi-line triple-quoted strings so the behavior is consistent with runtime.
  • Improved error reporting for "async with" statement. Added check that return result of __aexit__ is awaitable and improved error messages for the case where __enter__, etc. are present but have incorrect signatures.
  • Added support for bidirectional type inference for assignment statements that are assigning to an index expression that is subscripted by a slice.

Published 1.1.391

18 Dec 02:32

Choose a tag to compare

Bug Fixes:

  • Fixed a bug that results in a crash under certain circumstances when Self is errantly specialized.
  • Fixed bug that leads to incorrect evaluations when a ClassVar and Final qualifier are both used on the same dataclass attribute.
  • Fixed bug that leads to a hang when returning a tuple from a lambda argument expression in certain circumstances.
  • Fixed bug that results in incorrect evaluation of a generic dataclass entry when the entry is defined by a generic subclass.
  • Fixed bug that leads to a false positive error when --verifytypes is used and a subclass overrides an attribute that is generic in the base class.
  • Fixed bug that results in the command-line version of pyright not handling long file lists provided via stdin.
  • Fixed bug that results in spurious type evaluation error when an operator overload method like __add__ is implemented with a descriptor object.
  • Fixed bug that results in confusing error messages when using --verifytypes while targeting a submodule within a package and that submodule is a single-file module.
  • Fixed recent regression in isinstance type narrowing logic that affects the case where the filter type is a metaclass.
  • Fixed bug that results in order-dependent type errors under certain circumstances involving converter functions in a dataclass.

Enhancements:

  • Improved error message for incorrect exception type in an except clause.
  • Added exemption to the reportUnnecessaryComparison rule for simple wildcard patterns in a case clause.

Published 1.1.390

04 Dec 03:20

Choose a tag to compare

Bug Fixes:

  • Fixed recent regression that results in incorrect narrowed type when using the x in y pattern where y is a container type whose element type is Unknown or Any.
  • Fixed bug that causes a false positive overlapping overload error when the overload accepts a Callable[..., T] form.
  • Fixed a bug that results in a hang under certain circumstances when using a recursive type alias.
  • Fixed a bug that leads to a false positive when a function is decorated and has no explicit return type annotation and the body references the decorated function in a loop.
  • Fixed a bug that leads to incorrect type evaluation when __getitem__ is set to a callable object.
  • Fixed bug that results in confusing error message when there is a partially-unknown metaclass type detected by the --verifytypes command.

Enhancements:

  • Updated typeshed stubs to the latest version.
  • Added check for \u and \N escapes within bytes literals, which are illegal.
  • Added support for a "bare" Final annotation in a dataclass entry that has a default value assigned to it.
  • Improved dataclass converters to support generic types.
  • Added check for importing a Final variable from another module and then attempting to overwrite it.
  • Added check for an attempt to assign to a module-local variable if it is shadowing a Final variable declared by the builtins module or some other chained file.
  • Added support for evaluating the slice class type arguments for slice expressions.
  • Added check for invalid use of ClassVar qualifier within a NamedTuple or TypedDict attribute annotation.

Behavior Changes:

  • Changed inference logic for exception groups to more closely match the runtime. If a non-base exception is targeted, the inferred type is now ExceptionGroup rather than BaseExceptionGroup.

Published 1.1.389

13 Nov 06:45

Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a false negative if a | union operator creates a union of generic types. These types should be specialized with default type arguments.
  • Fixed bug that results in false negative when raising a value of type None.
  • Fixed bug that results in an incorrect type evaluation when a match statement uses a pattern with a target expression that overwrites the subject expression.
  • Fixed bug that results in a missing reportUnknownArgumentType error if the argument is an expression involving an __init__ parameter in an unannotated (pseudo-generic) class.
  • Fixed bugs that resulted in false positive errors when using an expression of the form type(A) as a base class or a metaclass in a class definition.
  • Fixed bug that leads to false positive when a method is overridden by a polymorphic method.
  • Fixed bug that affects pyproject.toml files with an emoji character by switching to a different toml parser.
  • Fixed a bug that results in a false negative when a class is used in a type annotation for a method parameter and both the class and the method are generic and use PEP 695 syntax.
  • Fixed a bug that results in a false positive "--verifytypes" error when using an explicit TypeAliasType call to create a public symbol in a "py.typed" library.
  • Fixed bug that results in the incorrect detection of an asymmetric descriptor if the descriptor class is generic.

Enhancements:

  • [From Pylance]: Improved signature help to skip keyword-only params with invalid names.
  • Added checks for except* clause to report invalid usage that is flagged as a syntax error at runtime.
  • Added check for the illegal use of an await keyword in a lambda.
  • Added missing checks for illegal use of await and async within list, set and dictionary comprehensions within a non-async function.
  • Improved a confusing error message that results when a class is assigned to an incompatible class.
  • Added narrowing support for a TypedDict value, which can be assumed never to be falsy if it has at least one required entry.
  • Improved the "x is y" and "type(x) is y" type guards to better handle the case where x is a TypeVar.
  • Updated typeshed stubs to the latest version.