Pyright

Latest version: v1.1.390

Safety actively analyzes 685838 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 15 of 81

1.1.310

Enhancement: Reimplemented handling of f-strings in accordance with PEP 701, which is included in Python 3.12.0b1. This is a significant change with potential for regressions.

Enhancement: Implemented `ReadOnly` TypedDict fields to explore proposed PEP 705 variant as discussed in this [discussion thread](https://discuss.python.org/t/pep-705-typedmapping/24827). This prototype will help inform which direction to take with PEP 705.

Bug Fix: Fixed regression that caused an internal assertion (and therefore a crash) when type checking a constructor whose arguments are not type compatible.

Bug Fix: Fixed bug that led to a "leaked" unsolved type variable if a `__new__` method used a function-scoped type variable and there was no `__init__` method for the class.

Enhancement: A class created with "NewType" should be treated as though it is implicitly `final`. The runtime enforces this. Pyright now correctly generates an error if such a class is used as a base class.

Bug Fix: Fixed a false positive error with the `reportImplicitOverride` check that occurs when the `override` decorator is applied to a method that is decorated with a wrapper function that completely replaces the original function with another.

Bug Fix: Fixed places in the pyright code where lists were being expanded on the stack, resulting in a stack overflow (and therefore a crash) if the list is too large.

Enhancement: Added special-case synthesis of the `update` method for a `TypedDict` class. For TypedDicts that include at least one read-only field, no updates are allowed. For TypedDicts that are writable, a "partial" type is synthesized that allows for any subset of keys (required or not required) to be passed to the `update` method.

Behavior Change: Changed protocol matching behavior for protocols that include a variable annotated as `ClassVar`. A class that defines this same variable as a "regular class variable" (one that is declared at the class level but can be overwritten on a per-instance basis) is now considered compatible with such a protocol.

Behavior Change: Changed type narrowing on assignment for member access expressions that involve an asymmetric `__getattr__` and `__setattr__` method. As with asymmetric descriptors, it is not safe in this case to assume that the written value will be the same as the read value.

Bug Fix: Fixed a bug that led to a false positive error in certain circumstances with nested call expressions where the expected type of the parameter was a union.

Behavior Change: Changed the behavior when a parameter whose type is a "naked" TypeVar has a default argument value. Mypy doesn't allow this case. Pyright allows it but previously modified the parameter type to be a union of the TypeVar and the type of the default argument. This behavior closed some type validation holes, but it created other problems and was very unintuitive for users. See https://github.com/microsoft/pyright/issues/3130. See https://github.com/microsoft/pyright/issues/2507 for a discussion that led to this original change. This change reverses this behavior. It potentially allows for some unsafe "creative" uses that will go unreported.

Bug Fix: Fixed recent regression that caused `useLibraryCodeForTypes` setting not to be applied if it was specified in the language server settings (as opposed to the config file).

Enhancement: Updated typeshed stubs to the latest version.

Bug Fix: Fixed bug that resulted in a false positive error when the "expected type" for a lambda is a function that includes a ParamSpec.

Bug Fix (thanks to LyricLy for the contribution!): Preserve parentheses around unary operators for printing.

Bug Fix: Fixed a couple of bugs in the method override consistency check that resulted in false positives when ParamSpecs were involved.

Bug Fix: Fixed bug that led to the incorrect type evaluation of an async generator when an `await` operator was used within a nested expression.

Performance: Addressed a performance issue that occurs when analyzing complex functions with deeply nested lambdas. This change adds a more sophisticated type caching mechanism that avoids emptying the cache when analyzing lambdas.

Performance: Added perf optimization to stripLiteralValue method to handle large unions comprised only of literal values.

Performance: Modified constraint solver to limit the number of subtypes in a union for the narrow bound of a type variable. Under certain rare circumstances, this can grow to a very large number and cause perf issues and hangs.

Bug Fix: Fixed a bug that caused an internal cache to be corrupted leading to a false positive error in specific circumstances.

1.1.309

Behavior Change: Reworked the logic for constructor type analysis to better mirror runtime behaviors of the `type.__call__` method. This is a big change with a potential for regressions.

Bug Fix: Fixed bug that led to a false positive under certain circumstances when assigning a value to a variable with a type annotation that evaluates to a descriptor type.

Bug Fix: Fixed a regression that resulted in incorrect type evaluation when passing an argument to a generic class constructor when the argument expression includes an "or" or "and" operator.

Enhancement: Extended the `reportUninitializedInstanceVariable` check to detect the case where a `final` class derives from an abstract base class (or hierarchy thereof) and does not implement one or more variables defined (but not assigned) in an ABC.

Enhancement: Implemented a check for an attempt to invoke a static or class method that is marked abstract.

Behavior Change: Deprecated command-line options 'typeshed-path' and 'venv-path' in favor of 'typeshedpath' and 'venvpath'. The hyphenated options were inconsistent with the conventions used for other options.

Enhancement: Added command-line option `pythonpath` that allows the path to the python interpreter to be specified.

Behavior Change: Updated support for `type` statement to conform with the latest updates to PEP 695. It now supports forward declarations, not just self references.

Enhancement: Added support for explicit calls to `TypeAliasType` constructor, as defined in PEP 695.

Behavior Change: Since PEP 696 won't make it for Python 3.12, pyright now enforces the Python 3.13 requirement for this capability (unless it's in a stub file or TypeVar, TypeVarTuple, and ParamSpec are imported from typing_extensions).

Performance: Changed import resolver to use sets and maps rather than arrays for tracking implicit imports. Arrays are fine if there are a few dozen implicit imports, but if there are thousands, they become a performance issue.

Performance: Added caching in import resolver for relative imports. Previously, we cached only absolute imports.

Performance: Added optimization to alias resolution that avoids the need to parse and bind a file in some cases.

Bug Fix: Fixed a bug that led to a false positive error in an edge case condition that involves an unpacked TypeVarTuple.

Enhancement: Added a check for f-strings that use nested braces in the "format specifier" portion (the section after a colon). This condition generates a syntax error at runtime, so it's useful for pyright to detect and report the error.

Bug Fix: Fixed a bug that results in a false positive error when using a dynamic base class in a `class` statement where the dynamic base class is based on a bound type variable.

Behavior Change: Changed pyright to reflect a recent decision about PEP 649 (deferred type annotations). The steering council tentatively approved PEP 649 for Python 3.12, but they recently decided to defer it until 3.13.

1.1.308

Behavior Change: Changed type inference logic that infers the type of the `value` attribute in an enum. If the enum class has a custom metaclass (one that is not part of the stdlib), pyright now assumes that the custom metaclass may perform some runtime magic that modifies the `value`. This occurs, for example, in django's `TextChoices` class.

Bug Fix: Fixed a bug that led to incorrect import resolution in cases where multiple import resolution paths have partial overlapping paths and some include namespace packages and others do not.

Bug Fix: Reworked the logic for bidirectional type inference to address several systemic issues with the previous mechanism when nested calls were used. This is a significant change, and it has the potential for regressions.

Bug Fix: Fixed a bug that led to the incorrect type evaluation of a generic function call if the return result included a type variable that evaluated to `Unknown`.

Bug Fix: Fixed bug that resulted in a bogus "fully-qualified name" of a symbol if used within a file that is located outside of the project and is not imported by a file in the project.

Bug Fix: Fixed a bug that resulted in incorrect fully-qualified names of type aliases that are nested within classes.

Enhancement: Added code to the "type printer" module that detects overlapping class and type alias names used within the same type. When these are detected, they are printed in their fully-qualified forms to help the user disambiguate.

Behavior Change: Added code to exempt the synthesized `__hash__` symbol in dataclass classes from override checks (such as `reportIncompatibleVariableOverride`).

Bug Fix: Fixed a bug in protocol matching that resulted in a false positive if `Self` was used in a method within a protocol base class used for another protocol.

1.1.307

Enhancement: Added support for type narrowing of TypedDicts with `NotRequired` entries with map patterns that use a literal str key pattern.

Behavior Change: Adjusted heuristic for dealing with ambiguous overloads due to unknown argument types. If one or both overloads include an `Any` in its return type, it now produces an `Unknown` result.

Bug Fix: Added support for constructors to PEP 712 mechanism.

Enhancement: Expanded special-case handling of `.value` and `.name` properties of `Enum` instance. It now handles non-literal cases by evaluating a union of all possible names or values defined in the enum.

Behavior Change: Changed behavior of logic that infers the type of the `value` and `_value_` members of an enum instance. If the `Enum` class defines a `__new__` method, these are evaluated as `Any` rather than a type based on their assigned value because the `__new__` method can transform the `value` in ways that cannot be determined statically.

Behavior Change: Modified the logic (and associated behavior) for constructor validation in cases where a metaclass has a custom `__call__` method. This is part of a larger effort to clean up constructor validation and make it more consistent with runtime behaviors.

Enhancement: Updated typeshed stubs to the latest version.

Bug Fix: Fixed a bug that resulted in a false positive error when binding a classmethod within a metaclass (i.e. a subclass of type).

Bug Fix: Fixed bug that caused any function or method named `deprecated` to be treated as though it behaved like `typing.deprecated` (introduced in PEP 702).

Behavior Change: Improved handling of `NewType` when `Any` is passed as a second argument.

Behavior Change: Made "Pyproject file has no pyright section" log message an "Info" message rather than an error to reduce noise.

1.1.306

Enhancement: Improved type evaluation of `yield from` expression so it handles operands that are unions.

Bug Fix: Added code to handle the case where a module uses an `from A.B.C import X` statement within the `A/B/C/__init__.py` module.

Bug Fix: Fixed a type evaluation bug that produces a false positive when using bidirectional type inference for nested call expressions when the target callables are generic.

Behavior Change: Reduced the default output of the CLI.

Bug Fix: Fixed a bug in the isinstance and issubclass type narrowing when the types have no overlap and one or both is `final`. In this case, the narrowing should result in a `Never` rather than an intersection type.

Bug Fix: Fixed a bug that resulted in a false positive error when constructing a tuple of classes in the second argument of an `isinstance` or `issubclass` call.

Bug Fix: Fixed a bug that resulted in false positive errors when overlapping roots were used in a multi-root workspace and new workspaces are added after one of these shared files was already open in the editor.

Bug Fix: Fixed a bug that resulted in a false positive error when doing protocol matching when there are multiple levels of protocol inheritance and a method that uses `Self` in its signature.

Bug Fix: Fixed inconsistent evaluation of a class type when calling a generic constructor that accepts a `type[T]` parameter and a union of classes is passed as an argument.

Behavior Change: Changed the behavior of the `reportIncompatibleMethodOverride` check to exempt the case where the base class or override has a type that is defined by `Callable[..., X]`. The `...` means that it's compatible with any signature. Also fixed a false negative in this check where the base method contains a `**kwargs` parameter but the override does not.

Bug Fix: Fixed bug that caused `useLibraryCodeForTypes` to default to false in the CLI if it was not overridden in the config file. Version 1.1.305 was intended to change the default to true, but it didn't.

Bug Fix: Fixed a confusing and inappropriate diagnostic addendum when a function with positional-only parameters is assigned to another function with positional-only parameters but has a parameter count mismatch. The old logic output an inappropriate message about a keyword-only parameter.

Bug Fix: Fixed a bug in the `--verifytypes` command-line tool that affected the case where a submodule was specified (e.g. `--verifytypes a.b.c`) and the final nested module was a single file (e.g. `c.py`) rather than an `__init__.py` within a folder.

Enhancement: Added support for a generic `NamedTuple` class — i.e. a class that uses `NamedTuple` as a base class along with type parameters defined in a `Generic[...]` base class and then uses these type parameters in type definitions for the `NamedTuple` entries.

Enhancement: Implemented check for conditional statement operands. Such operands must support a `__bool__` method that returns a `bool` return type. Any other type is treated as an error by the runtime.

Enhancement: Added special-case handling for methods within generic classes parameterized by a ParamSpec when those methods use `*args: P.args, **kwargs: P.kwargs` in their signature and the callable signature captured by the `ParamSpec` is from a generic function. In this case, the TypeVar scope of the captured function is retained so its type variables can be solved when the method is solved. This is useful for generic callback protocol classes that implement a `__call__` method.

Enhancement (by debonte): Added provisional support for [draft PEP 712](https://peps.python.org/pep-0712/), which introduces support for a `converter` parameter in a field descriptor for `dataclass` and `dataclass_transform`.

Bug Fix: Eliminated the code that treats unions within value expressions as a `UnionType` object. This behavior caused various problems including a false positive in some cases.

1.1.305

Bug Fix: Fixed a bug that resulted in incorrect type comparison results (which led to incorrect type narrowing) when `Annotated` was used in some circumstances.

Bug Fix: Fixed bug that led to a false positive error when a ParamSpec captures a signature that includes an `*args` or `**kwargs` and then is called using an unpacked iterable (for `*args`) or an unpacked Mapping (for `**kwargs`).

Enhancement: Added diagnostic for ` pyright` comment that controls file-level settings that is not on its own line (i.e. doesn't start in column 1).

Bug Fix: Fixed bug that resulted in a false positive error when importing a type alias via a wildcard import.

Bug Fix: Fixed bug in inference of generator function return type that led to false positive error. The "send" type (the second of three type arguments for a `Generator`) cannot be inferred precisely, so it should be `Unknown` rather than `None`. Modified the "send type" type inference logic for generators. Instead of always inferring `Unknown`, pyright now infers `Any` if the send type is provably never used within the generator. This is a common case and allows the generator function return type to be inferred without an `Unknown` partial type in most cases.

Bug Fix: Fixed a bug that led to a false positive error when a partially-specialized generic function with a ParamSpec is further specialized such that the `ParamSpec` is bound to `...` (i.e. the ParamSpec equivalent of `Any`).

Enhancement: Improved handling of bidirectional type inference for call expressions in the case where the target call returns a callable and the expected type is a union that includes some non-callables. The logic now filters out the non-callables to enable bidirectional type inference to succeed in cases where it previously didn't.

Bug Fix: Fixed a type evaluation bug involving the `tuple` constructor call when used with bidirectional type inference, specifically when the expected type is a union of tuples.

Enhancement: Updated typeshed stubs to the latest version.

Enhancement: Improved error message for binary operators that don't use union expansion.

Bug Fix: Fixed a bug that resulted in a false positive "is partially unknown" error when using an overloaded function whose implementation was partially unknown. Only the overloads should be considered in this case.

Behavior Change: Changed `reportUninitializedInstanceVariable` check to exempt subclasses of `ABC` that are not marked `final`. It already exempted Protocol classes.

Bug Fix: Fixed type evaluation bug that led to a false positive in cases involving bidirectional type inference of a constructor whose type variable is invariant and the argument is a dictionary, set, or list expression.

Page 15 of 81

Links

Releases

Has known vulnerabilities

© 2024 Safety CLI Cybersecurity Inc. All Rights Reserved.