Skip to content

Releases: microsoft/pyright

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.

Published 1.1.365

29 May 04:18
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed regression that results in the incorrect type evaluation for the value attribute of a StrEnum or IntEnum class.
  • Fixed a bug that results in incorrect type compatibility checks for a callable that uses *args: *tuple[T, *tuple[S, ...]].
  • Fixed a bug that results in an unsolved TypeVar when calling list(tuple()).
  • Fixed bug that leads to inconsistent narrowing-on-assignment behavior when a tuple instance with unknown type arguments is assigned to a target symbol with a declared tuple type.
  • Fixed bug that results in a false negative when a Final class variable is assigned a value in the class body and reassigned a value in the __init__ method.

Behavior Changes:

  • Changed tuple expression inference behavior to not preserve literal entry types if the tuple expression is embedded within another tuple, set, list, or dictionary expression.
  • [Contribution by @ujan-r] Use typeshed version info for stdlib module list.

Enhancements:

  • Improved diagnostic messages for parameter mismatch.
  • Added support for configuration inheritance through an "extends" configuration option.
  • Added support for custom ".toml" files specified via the -p option on the command line.

Published 1.1.364

22 May 02:13
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed bug that results in a false negative syntax error when a PEP-695 type alias uses a keyword as a name.
  • Fixed a bug that leads to a false positive error when first argument to super call is an instance of a metaclass.
  • Fixed recent regression that results in a false positive when accessing an enum member from an instance of an enum class.
  • Fixed bug that results in a false negative when determining if a callable type is compatible with another callable type and the first has a *args parameter and the second has a single positional+keyword parameter.
  • Fixed a bug in the code flow engine that results in incorrect type evaluation in certain cases involving codependent variables in a loop.
  • Fixed a bug that results in incorrect type narrowing for a type guard function that uses TypeIs[type[T]].
  • Fixed regression related to "converter" field parameter for dataclasses when the converter refers to a generic class constructor.
  • Fixed a bug that results in a false negative when a generic function has a parameter with a generic type and a default argument value. This could lead to a typing hole when considering subtyping rules for callables.
  • Fixed a bug in the dataclass "converter" support that resulted in an error if the converter is tuple.
  • Fixed regression that results in incorrect type evaluation for annotations that involve nested protocols (such as P[P[T]]).
  • Fixed a bug that resulted in an infinite loop when a function that uses an *args: *Ts parameter is passed as an argument to itself.
  • Fixed bug that leads to a false negative when calling a callback function that returns a callable with a generic parameter type.

Behavior Changes:

  • Changed the handling of Enum subclasses that explicitly override value or name to avoid using the special-case logic for computing these types. This is done regardless of whether the class uses a custom metaclass.
  • Changed support for dataclass "converter" field parameter to be off by default. The "enableExperimentalFeatures" must now be enabled to use this feature. If and when PEP 712 is approved, it will be moved out of experimental.
  • Added support for using Literal and various other special forms in a value expression.

Enhancements:

  • Added support for recent addendum to typing spec that provides a special case for dataclasses so ClassVar and Final can be used together to distinguish between a regular Final instance variable and a ClassVar that is also Final.
  • Updated typeshed stubs to the latest version.
  • Improved type printer (the component that converts an internal type to textual format for diagnostic messages) so it better handles special forms like Literal or unions when used in a value expression.

Published 1.1.363

15 May 05:02
Compare
Choose a tag to compare

Bug Fixes:

  • Updated manifest to reflect the correct default value for reportInvalidTypeForm.
  • Fixed bug that resulted in diagnostics associated with the reportUnnecessaryTypeIgnoreComment check to not include the error code.
  • Fixed bug that causes a false positive reportPrivateUsage error when a global or nonlocal binding is used within a class to access an outer-scoped variable.
  • Fixed bug that results in a false positive reportUnnecessaryComparison when a variable is used in a conditional expression and its type is a union that includes a Coroutine and a non-coroutine.
  • Fixed false positive deprecatedTypingAliases deprecation for collections.abc.AbstractSet due to a recent change in typeshed stubs.
  • Fixed recent regression that results in assert_type failure when a class is parameterized by a ParamSpec with a default value.
  • Improved handling of constrained TypeVars when used with unary operators.
  • Fixed bug that results in incorrect type narrowing for a tuple with determinate length when indexed with an out-of-bounds slice.
  • Fixed bug that results in incorrect type narrowing for isinstance or issubclass type guard when the filter is a generic class whose type parameter has a default value.
  • Fixed bug that results in incorrect type evaluation behavior within class body of an enum class when one enum member is used to define another enum member. This involved a significant rewrite of the logic involving enum symbol evaluation.
  • Fixed a bug that results in a false positive error when a decorator is applied to a property.
  • Fixed bug that resulted in false positive when evaluating a function call involving a TypeVarTuple under certain circumstances.
  • Fixed a bug that results in incorrect type evaluation when a function parameterized with a TypeVarTuple is passed as an argument to another function parameterized with a TypeVarTuple.

Behavior Changes:

  • Deferred execution of type annotations (PEP 649) did not make it into Python 3.13 and has been deferred (again) until Python 3.14. Changing pyright's logic accordingly.
  • Changed the type evaluation for type(Any) or type(x) where x is a value of type Any or Unknown. These now evaluate to type[Unknown].
  • Changed the TypeVar scoping behavior for TypeVars that appear only within a Callable subtype within a function's declared return type. Previously, pyright scoped these TypeVars to the Callable rather than the function. This was due to issue #4285. I'm reversing this decision because it's not spec-compliant, creates a bunch of unnecessary complexity, and results in buggy behavior.

Published 1.1.362

08 May 05:43
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that results in incorrect type narrowing when a match statement uses an empty (zero-element) sequence pattern and the subject expression type is a tuple that potentially (but does not always) have a zero length.
  • Fixed a crashing bug that results from an internal assertion failure when a generic class that uses PEP 695 syntax is located within an unreachable code block.
  • Fixed a bug that results in incorrect type narrowing in the negative (fall-through) case when a match statement includes a class pattern with a runtime-checkable protocol class.
  • Fixed recent regression with the TypeIs type guard that resulted in incorrect type narrowing in the negative (else) case.
  • Fixed a bug that results in incorrect type evaluation for a variable that uses a nonlocal or global binding within an inner scope. Such a variable should never honor the narrowed type from the outer scope.
  • Fixed false positive when a TypeVar appears within a function type comment.
  • Fixed incorrect type narrowing for a class pattern argument if the class is a generic whose type parameters have default values.
  • Fixed recent regression that resulted in incorrect type narrowing when a *args: P.args parameter was used in the expression len(args) >= x.
  • Fixed a bug that resulted in a false negative when a Literal with multiple arguments is used in a value expression. It should be treated as a UnionType special form in this case.

Enhancements:

  • Addressed a performance issue when indexing into a value that has a type consisting of a union of many (dozens or hundreds) of tuple types.
  • Updated typeshed stubs to the latest version.

Behavior Changes:

  • Changed interpretation of function definitions with (*args: Any, **kwargs: Any) to be ... in compliance with latest typing spec.
  • Added special-case handling for __init_subclass__ checks for classes that have ABCMeta as a metaclass. Previously, these were exempted from __init_subclass__ because ABCMeta has a custom __new__ method, but we know that this metaclass calls through to type.__new__ which calls __init_subclass__.

Published 1.1.361

01 May 01:57
Compare
Choose a tag to compare

Bug Fixes:

  • Fixed a bug that results in a false negative when using bidirectional type inference to evaluate the type of a lambda expression if the expected type is a union of two or more callables.
  • Fixed bug caused by incorrect synthesis of item and keys attributes for named tuple classes.
  • Fixed bug that resulted in incorrect bidirectional type inference when calling a constructor for a generic class that defines no __new__ or __init__ method.
  • Fixed bug that results in a false positive error when a yield statement is used within a lambda following a function.
  • Fixed a bug that led to poor performance (effectively a hang) if an unannotated function is called through many (greater than 8) call expressions within a loop using different literal-value arguments each time.
  • Fixed a bug that results in a false positive error when using __extra_items__ (PEP 728) with a TypedDict imported from typing_extensions.
  • Fixed a bug that leads to an infinite loop when performing protocol matching under certain circumstances that involve recursive protocol definitions.
  • Fixed a bug that results in a false positive error when Callable() is used as a class pattern and the subject type is Any or Unknown.
  • Fixed a false negative that occurs when reassigning a Final variable within a class body.
  • Changed the tokenizer so it is bug-for-bug compatible with the CPython tokenizer in versions 3.10 and newer in the case where a backslash (continuation character) is located by itself on a line.
  • Fixed a bug that results in incorrect type evaluation when a global (module-scoped) variable is captured within an inner scope and the variable is not modified anywhere below the inner scope. It's possible in this case for the variable to be modified by code outside of the module.
  • Fixed bug that resulted in incorrect evaluation of an identifier used in a method parameter type annotation if it shadows a forward reference in a class scope when the method is using PEP 695 type parameters.
  • Fixed a bug that results in a false negative when an Unpack is used in a union. This isn't allowed.
  • Fixed bug that produces incorrect output when converting to a textual representation the type type[Foo] where Foo is a type alias.

Behavior Changes:

  • Changed logic that synthesizes the constructor methods for a NamedTuple subclass (using the class syntax) so the __new__ method contains parameters based on field names and the __init__ method contains a general *args: Any, **kwargs: Any parameter signature. Previously, this was swapped, but the new way is more faithful to the runtime.
  • Changed TypeIs to use the same logic as isinstance type narrowing logic for consistency.