Skip to content

Releases: microsoft/pyright

Published 1.1.400

23 Apr 04:29
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a false positive when accessing a generic attribute from an object whose type is type[X].
  • Fixed bug that results in incorrect type narrowing of a variable that is shadowed in an inner-scoped comprehension.
  • Fixed bug that results in a false positive error when referencing a class-scoped type alias defined as a callable.
  • Fixed bug that causes bidirectional type inference not to be used in cases where a ternary expression is assigned to an annotated instance or class variable and the ternary condition narrows the type of self or cls.
  • Fixed bug that results in a spurious "type already specialized" error when using a class-scoped type alias defined using a type statement or TypeAliasType constructor.
  • Fixed a bug that leads to a hang when a generic type alias definition refers to itself.
  • Fixed a bug that results in missing diagnostic details under certain circumstances where bidirectional type inference is attempted in the assignment of an attribute.
  • Fixed a bug that results in a false positive error when calling a function with an unpacked TypedDict with extra_items when additional keyword args are passed.
  • [From pylance] Fixed regression introduced in 1.1.399 that caused pyright CLI to fail to run on Linux systems.

Enhancements:

  • Extended "type(x) is C" type narrowing logic to support cases where C is a union of types or a type variable with a union upper bound.
  • Added support for PEP 765, which makes it a syntax error (or warning) in Python 3.14 if a return, break or continue is used to exit a finally clause.
  • Added check for named tuple field names that begin with an underscore. These result in a runtime exception.

Behavior Change:

  • Reverted a recent change that extended the reportPrivateImportUsage check to enforce imports from submodules whose names begin with an underscore. This change was disruptive to users of the popular pandas library because it exports a submodule named _typing. This was originally intended to be experimental or private, but it was never fully addressed. The pandas maintainers will work to fix this issue (pandas-dev/pandas#55231) over the next year. I'm going to back out this change to pyright in the meantime.

Published 1.1.399

08 Apr 19:11
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in incorrect type narrowing when a value whose type is a non-callable (and non-final) class is passed as the second argument to an isinstance call and the first argument is a callable type. In this case, a subclass could provide a compatible __call__ method, so the type shouldn't be narrowed to Never.
  • Fixed bug that results in a false positive "missing stub file" diagnostic when importing a "py.typed" submodule from a namespace package.
  • Fixed bug that results in a false negative when a type variable with an upper bound is used to annotate a parameter in a method override.
  • Fixed a bug that results in a false negative for a method override that uses Self in a contravariant position.
  • Fixed bug that results in a false positive error under certain circumstances involving a type variable with an upper bound of type[T] that is assigned to another type variable.
  • Fixed a bug that results in a false negative when the specialization of a TypeVarTuple includes multiple unpacked tuples of unknown length.
  • Fixed a bug that results in a false negative when a class that derives from type[Any] is assigned to any other type.
  • Fixed bug that results in an incorrect error under certain circumstances when inferring the return type of a recursive function that has a decorator or is async.
  • Fixed bug that results in a false negative when a return statement contains a call expression that invokes a NoReturn call and the argument list contains errors.
  • Fixed bug that leads to a false positive in the reportUnnecessaryComparison check when one operand's type is a callable and the other is not.
  • [From pylance] Fixed a bug that results in an internal assertion (and therefore a crash) when __builtins__.pyi imports from a project file.

Enhancements:

  • Extended deprecateTypingAliases feature to support symbols imported from typing_extensions.
  • Extended reportUnknownVariableType check to include cases where a value whose type is a generic class parameterized by Unknown is assigned to a variable with a declared type.
  • Extended the check for isinstance and issubclass argument validation to flag the Literal special form, which leads to a runtime error when used in the second argument.
  • Updated typeshed stubs to the latest version. This version removes support for Python 3.8, which is now out of service.

Behavior Changes:

  • Removed support for ru and ur string prefixes. These were supported in Python 2.7 but are syntax errors in Python 3.x.

Published 1.1.398

26 Mar 03:43
Compare
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
Compare
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
Compare
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
Compare
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
Compare
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
Compare
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
Compare
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
Compare
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.