pyright

Static Type Checker for Python

OTHER License

Downloads
2.3M
Stars
13.2K
Committers
119

Bot releases are visible (Hide)

pyright - Published 1.1.362

Published by github-actions[bot] 5 months ago

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__.
pyright - Published 1.1.361

Published by github-actions[bot] 6 months ago

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.
pyright - Published 1.1.360

Published by github-actions[bot] 6 months ago

Enhancements:

  • Added support for @deprecation messages for decorators that wrap a function in a callable object. The deprecated message is now propagated through the ParamSpec and the __call__ method.
  • Updated typeshed stubs to the latest version.

Behavior Changes:

  • Moved check for invalid use of class-scoped TypeVar within a self annotation in __init__. It was previously reported under reportGeneralTypeIssues, but it's now moved to reportInvalidTypeVarUse. This was done to help typeshed maintainers migrate away from this pattern.
  • Changed behavior to no longer exempt unguarded access to not-required TypedDict member within a try or with block. Previously, such errors were exempt, but this is inconsistent with other type checks in pyright which eschew the practice of using exception handling for normal code flow.

Bug Fixes:

  • Fixed recent regression that affected unannotated __call__ methods in a metaclass. This change aligns pyright's behavior to the typing spec.
  • Fixed recent regression that incorrectly narrowed the type of kwargs when used in a type guard of the form if "a" in kwargs.
  • Fixed bug in protocol matching that results in a false positive when the subject object is a dataclass that contains a callable. It should be considered an instance member in this case, so it should not be bound to the class.
  • Fixed a bug that results in a false positive error when bidirectional type inference is used for a dictionary comprehension when the expected type is a union.
  • Redesigned the handling of PEP 695-style type parameter scoping to better match the CPython runtime implementation. This fixes multiple bugs with type parameter symbol resolution. For example, if a type parameter is quoted as a forward reference.
  • Fixed bug that leads to false negative when binding an object to an overloaded method where all of the overloads have incompatible self parameter types.
  • Fixed bug that leads to incorrect metatype for a class object that is created by calling the metaclass with a two-argument form.
pyright - Published 1.1.359

Published by github-actions[bot] 6 months ago

Enhancements:

  • Expanded support for len(x) == L type guard pattern (where x is a tuple) to support <, <=, > and >= comparisons as well.
  • Improved some diagnostic messages, moving away from the term "member" to prefer "attribute". Switched from "cannot assign to type" to "incompatible with type" for consistency and clarity.
  • Extended type narrowing logic for in and not in operators that target TypedDicts to also support constrained TypeVars that use TypedDicts as value constraints.
  • Added a check for the case where a frozen dataclass overrides a field from its parent class but doesn't provide a default value (where its parent does). This can result in a type violation if the parent's default value is not compatible with the child's (covariant) field type.

Behavior Changes:

  • Changed behavior when evaluating the upper bound expression, value constraints expression, or default expression for a PEP-695 type parameter. At runtime, these are always evaluated in a deferred manner even if they are not quoted. Pyright now follows the runtime behavior.
  • Modified handling of annotated self parameter in __init__ method when evaluating constructor call so pyright conforms to the latest typing spec.
  • Added missing check for the errant use of class-scoped type variables in a type annotation for the "self" parameter within an "init" method. The typing spec now clarifies that this is illegal and should generate an error.
  • Updated logic for converting a class constructor to a callable to conform to the newly-updated typing spec.
  • Changed the behavior when invoking constructor for type[T] where T is a TypeVar with no explicit upper bound (and therefore has an implicit upper bound of object). According to the newly-clarified typing spec, this should enforce the constructor signature of object.
  • Modified behavior in constructor call code that previously applied some (now non-compliant) heuristics to reconcile a metaclass __call__ method with a __new__ method. The new behavior is now compliant with the typing spec.
  • Changed behavior of conversion from class constructor to callable to conform with the typing spec in the case where the __new__ method of the class returns a value that indicates the __init__ method should be ignored.
  • Changed behavior of conversion from class constructor to callable to conform to honor the annotated type of self in the __init__ method.
  • Changed behavior of conversion from class constructor to callable to conform to honor return type of the __new__ method.

Bug Fixes:

  • Fixed a bug that leads to inconsistent behaviors when an assignment leads to a type violation. When assigning to a local variable, the target expression is not "narrowed" to include the assigned type in this case. The new behavior applies this same behavior when assigning to instance or class variables.
  • Fixed recent regression that results in a false positive error when applying a @property decorator to a method that has already had a decorator applied to it.
  • Fixed bug that results in a spurious reportAbstractUsage error when an abstract class is captured through a type[T].
  • Fixed bug that results in incorrect type evaluation when solving a ParamSpec type when there are multiple constraints provided.
  • Fixed a bug that results in incorrect type evaluation when assigning a function with a NoReturn return type to a Callable[..., T].
  • Fixed a bug that leads to a false negative when an unparenthesized assignment expression is used in a dictionary key within a dictionary expression or comprehension.
  • Fixed bug that results in false positive error under certain circumstances that involve unions of TypeVars in an invariant context.
pyright - Published 1.1.358

Published by github-actions[bot] 6 months ago

Bug Fixes:

  • (from Pylance): Fixed a bug that caused a crash under certain circumstances when an import cannot be resolved.
  • Fixed non-compliance issue with TypeIs, which is documented to have an invariant type parameter.
  • Fixed a bug that results in incorrect type evaluation when a sequence pattern in a match statement includes a * element and the subject includes a tuple with an element with indeterminate length.
  • Fixed bug that results in an intermittent false positive "circular dependency" error for fields within a dataclass.
  • Fixed a bug that results in a false positive error under certain circumstances when a TypeVar or TypeVarTuple is being solved with literal values in both an invariant and non-invariant context.
  • Fixed bug that results in incorrect type evaluation in cases where a generic function returns a callable, and the function is called with a higher-order generic function as an argument.
  • Fixed a bug that results in a false negative when a generic function returns a Callable type that is specialized to include a live (in-scope) type variable.
  • Fixed bug that results in inconsistent type narrowing on assignment based on whether the assignment occurs within the same statement that includes the (declared) type annotation for the variable and whether the type annotation is provided as a type comment.

Enhancements:

  • Added optimization for TypedDict type assignments. Under certain circumstances (e.g. when comparing large unions of TypedDict types), this can save significant time.
  • Modified the handling of enum class attributes so those with private (mangled) names are exempted from being considered enum members. This reflects the runtime behavior.
  • Added support for narrowing of subject subexpression within a match statement for references to the subexpression after the completion of the match statement.
  • Updated typeshed stubs to the latest version.
  • Improved error handling for quoted annotations. Bytes, raw strings, and f-strings are not allowed according to the typing spec.
  • Added an error message for a Literal type annotation that includes a string with a named unicode escape sequence. These are not supported.
pyright - Published 1.1.357

Published by github-actions[bot] 7 months ago

Bug Fixes:

  • Fixed bug that results in a false positive error when explicitly calling __new__ on a dataclass, namedtuple, or TypedDict. These classes all require synthesized __new__ methods.
  • Fixed bug that results in false negative when a __new__ or __init__ method cannot be bound without a type violation.
  • Fixed a bug that results in incorrect type narrowing of enums that derive from enum.Flag.
  • Fixed a type hole when a dictionary expression includes a dictionary expansion operator that acts on a non-closed TypedDict.
  • Fixed bug that results in a type not being narrowed when using the K in TD type guard pattern (where TD is a TypedDict and K is a literal key). Narrowing was skipped if the RHS operand was not a simple identifier.
  • Fixed inconsistent handling of literal values in a list comprehension.
  • Fixed a bug that results in a false positive error when an unpacked TypeVarTuple is used in a function defined with PEP-695 syntax.
  • (From Pylance) Improved heap usage tracking within language server to reduce the likelihood of crashes related to heap exhaustion.
  • Fixed a bug that results in incorrect inferred parameter types for an unannotated method in a subclass when the parent class method contains function-scoped TypeVars.

Enhancements:

  • Added support for negative (fall-through) type narrowing for subject subexpressions in match statement when subject consists of a tuple expression and patterns exhaustively match the tuple.
  • Enhanced dictionary type evaluation to support dictionary items that overwrite previous dictionary items. Only the last value type is now considered, so if previous values (which are overwritten) would otherwise violate typing rules, this no longer generates a type error.
  • Enhanced discriminated class support to include not only literal field values but also None.
  • Improved diagnostic message for access to unknown member in the case where the user probably meant to access an item in a TypedDict but used a member access expression rather than an index expression.
  • Improved return result for synthesized get method for closed TypedDict classes (as defined in PEP 728).
  • Refactored tokenizer and parser output to help reduce the amount of memory needed.

Behavior Changes:

  • Changed the handling of Final variables (that are not explicitly marked ClassVar) within dataclass class bodies. This is consistent with the runtime and this proposed change to the typing spec.
pyright - Published 1.1.356

Published by github-actions[bot] 7 months ago

Bug Fixes:

  • Fixed bug that results in a false positive error when a class-scoped TypeVar with a default that references another class-scoped TypeVar is used in a method signature in that class.
  • Fixed bug that resulted in a false positive error if a PEP-695 type statement uses a type parameter and encloses the RHS in quotes.
  • Fixed bug that results in incorrect type narrowing in the negative (fall-through) case when a runtime-checkable protocol class is used as a class pattern with arguments within a match statement.
  • Fixed a bug that results in a false positive when a class-scoped TypeVar used within a method has a default that refers to another class-scoped TypeVar.
  • Fixed a bug that results in a false positive reportImplicitOverride diagnostic if the class derives from an Unknown or Any class.

Behavior Changes:

  • Tweaked bidirectional type inference behaviors for lists to improve certain inference cases.
  • Changed the logic for metaclass instance variable lookups to ignore the lookup if the metaclass MRO contains an unknown class.

Enhancements:

  • Update Unicode range tables to match Unicode 15.1.
  • Added check for the use of a non-runtime-checkable protocol class in a class pattern. This generates an exception at runtime.
  • Updated typeshed stubs to the latest version.
pyright - Published 1.1.355

Published by github-actions[bot] 7 months ago

Bug Fixes:

  • Fixed a bug that results in incorrect type evaluation if a list expression includes a generator expression.
  • Fixed bug that results in a false negative when a TypeAliasType object is used in a class pattern.
  • Fixed bug that results in false positive when implicitly specializing a class parameterized by a TypeVarTuple when there is no default.
  • Fixed bug that results in false positive when a list or set expression is evaluated using bidirectional type inference when the expected type is MutableSet or MutableSequence.
  • Fixed bug that results in a false negative when overriding a method that has keyword parameters with a method that has a *args parameter.
  • Fixed a bug that results in a false positive error in certain circumstances involving a TypeVarTuple used within an overload.
  • Fixed bug that results in a false positive error when a base class defines a writable property and a subclass writes to the property.
  • Fixed bug that results in a false positive "overload implementation does not match overloads" diagnostic when positional-only and keyword-only parameters are involved.
  • Fixed a bug that results in a false positive in a complex situation that involves generic protocols, properties, and mix-in classes.
  • Fixed bug that results in false positive error when a __new__ method in a metaclass uses PEP 692 (unpacked TypeDict) to annotate its **kwargs parameter.

Enhancements:

  • Updated typeshed stubs to the latest. This version of typeshed replaces the older-style positional-only parameters with PEP 570 syntax.
  • Improved validation for except and except* statements to catch some previously-undetected invalid cases.
  • Expanded handling of python versions to handle more than just major/minor version numbers. Pyright now handles micro, releaseLevel, and serial numbers as well.
pyright - Published 1.1.354

Published by github-actions[bot] 7 months ago

Bug Fixes:

  • Fixed a bug that resulted in an incorrect type evaluation when an augmented assignment is used within an inner-scoped function to add a constant to a variable. Literal math should not be used in this case.
  • Fixed two bugs that resulted in false negatives when redefining a constant variable with a non-variable symbol and when redefining a Final variable with a non-variable symbol.
  • Fixed bug that results in false positive when a generic class or type alias uses a TypeVarTuple followed by one or more ParamSpecs that have default values.
  • Fixed bug that resulted in false negative when narrowing a constrained or bound TypeVar with a complex() or float() class pattern.
  • Fixed bug that results in a false positive under certain circumstances when a constrained TypeVar is used as the default for another constrained TypeVar.
  • Fixed a bug that results in a false positive under certain circumstances when defining a type alias using the old typing.TypeAlias annotation.
  • Fixed a bug that results in a false negative when a class explicitly inherits from a protocol that defines an instance variable but the child re-declares as a ClassVar without an explicit type.
  • Fixed a bug that made locale overrides through environment variables no longer work on node 21.

Enhancements:

  • Enhanced handling of type function when it is passed a class. Pyright previously evaluated this as Any, but now it returns the class' metaclass.
  • Added check for generic classes and type aliases that include a TypeVarTuple followed by a TypeVar that has a default value. This is illegal according to PEP 696.
  • Changed the behavior when accessing a class attribute from a generic class that is not specialized. The class is now automatically specialized in the case using default type parameter values (from PEP 696) or Unknown. This change is required for conformance with PEP 696.
  • (From pylance) Added some optimizations to the tokenizer to reduce memory usage.
  • Added new reportUnhashable diagnostic rule.
pyright - Published 1.1.353

Published by github-actions[bot] 8 months ago

Breaking Changes:

  • The CLI and language server versions of pyright now require a minimum node version of 14. Previously node 12 and 13 were supported.

Enhancements:

  • Enabled PEP 705 and PEP 696 functionality without the use of enableExperimentalFeatures now that these PEPs are officially accepted.
  • Improved support for instance variables whose type is declared in a metaclass. Pyright now honors this type and enforces type consistency in derived classes.

Bug Fixes:

  • Fixed a bug that results in a false negative when a dundered method overrides a base class method of the same name and uses different parameter names along with different types.
  • Fixed a bug that leads to a false positive error when a match statement is used in a loop and the subject expression is potentially narrowed as a result of the match statement.
  • Added check for inappropriate use of Annotated passed as second argument to NewType call.
  • Fixed a bug that results in a false positive error when expanding the type arguments to a TypeVarTuple under certain circumstances.
  • Fixed a bug that results in incorrect type evaluation when an index expression is assigned a value within a doubly-nested loop under certain circumstances.
  • Fixed a regression that caused the signature help provider to not display the __new__ method of a constructor if it is overloaded.
  • Fixed hard-coded type information for module attribute __package__. It should be str | None rather than str.
  • Fixed a bug in the isinstance type guard logic. It was not properly handling tuples that included unions.
  • Fixed bug in signature help provider so str method docstrings are showed when called on LiteralString.
  • Fixed a bug that results in incorrect type narrowing behavior for member access expressions under certain circumstances.
  • Fixed bug that resulted in a false negative when a possibly-unbound variable is captured by an inner scope under certain circumstances.
pyright - Published 1.1.352

Published by github-actions[bot] 8 months ago

Enhancements:

  • Implemented provisional support for PEP 728 (support for extra items within TypedDicts). You must set enableExperimentalFeatures to true for now.
  • Added support for concatenated strings used in a @deprecated decorator.
  • Added support for call-site return type inference for class and instance methods.
  • Improved handling of enum.nonmember in cases where the attribute has a declared type.
  • Added missing check for inappropriate use of InitVar outside of a dataclass.

Behavior Changes:

  • Added special-case handling for 'typing_extensions' module whose stubs are part of typeshed's stdlib stubs even though it is not part of stdlib.
  • Refined the heuristic for when to use bidirectional type inference for the RHS of and and or operators.
  • Changed behavior of command-line "--pythonversion" and "--pythonplatform" options so they now override the same-named options in the config file.

Bug Fixes:

  • Fixed a bug that resulted in a false negative when attempting to use TypedDict or Protocol as an upper bound when using PEP 695 syntax.
  • Fixed a bug that resulted in "reportUnnecessaryTypeIgnoreComment" diagnostics to be generated even if the source file was in the "ignore" list.
  • Fixed a bug that leads to incorrect type inference for a lambda when passed to a constructor in certain circumstances.
  • Fixed a bug that leads to a false positive type violation when reassigning a value within a loop and the target variable has a declared type of a constrained type variable.
  • Fixed a bug that results in a false negative when passing an unpacked dict of the wrong type to a function that contains a positional-only parameter marker plus one or more keyword parameters.
  • Fixed a bug in the import resolver that resulted in an incorrect resolution when an import within a __init__.py file uses the form from .a import a.
  • Fixed a bug that results in a false positive error when an await expression is passed as an argument to an overloaded function.
  • Fixed a bug that results in an incorrect "Unbound" type evaluation for a variable assigned within a loop.
pyright - Published 1.1.351

Published by github-actions[bot] 8 months ago

Bug Fixes:

  • Fixed bug that results in a false positive "no overload implementation" error if an overloaded function is passed through a decorator that uses a ParamSpec.
  • Fixed a recent regression that results in a false positive error when an Enum subclass overrides __new__ or __init__ and then a subclass of that class assigns tuple values when defining enum members
  • Fixed a bug that results in a false positive error when a method defined within a named tuple is overridden by a subclass
  • Fixed a bug that results in a false positive error when a enum.nonmember value is assigned to a class-scoped variable with a type annotation in an Enum class.
  • Fixed a bug in the type narrowing logic for class pattern matching that resulted in incorrect narrowing in the negative (fall-through) case.
  • Added missing check for inappropriate use of an unpacked TypeVarTuple within a TypeAliasType type parameter list.
  • Fixed a false positive reportUnknownArgumentType error when assigning an empty list or dict expression to an index expression subscripted with a slice.
  • Fixed bug that results in a false positive error when assigning a tuple value that includes an unpacked TypeVarTuple to another tuple that also includes an unpacked TypeVarTuple.
  • Fixed bug that results in a false positive error when calling update on a TypedDict with zero defined entries.
  • Fixed a bug that results in a false positive with the reportUnnecessaryCast check if the second argument is a special form.
  • Fixed a bug that led to incorrect type evaluation for a call that targets a generic function that uses a default argument for one of the generic parameters.

Behavior Changes:

  • Change the heuristic for determining whether a metaclass supports __or__. In the case where the metaclass derives from Any or Unknown, pyright now assumes that it doesn't override __or__.
  • Changed behavior of CLI's --watch mode. Previously, it reported diagnostic deltas when it detected a change, but it is more useful if it reports all remaining diagnostics even for files that it didn't reanalyze due to a file change.

Enhancements:

  • Updated typeshed stubs to the latest version.
  • Added provisional support for draft PEP 742 (TypeIs).
  • Added check for the use of an implicit position-only parameter (one that starts with a double underscore) that is located after a non-position-only parameter.
pyright - Published 1.1.350

Published by github-actions[bot] 9 months ago

Bug Fixes:

  • Fixed a bug that resulted in an incorrect type evaluation when a TypeVar with a default (PEP 696) was used in an overload but was not solved.
  • Fixed a bug that results in a false negative when a None type is included in an unpacked argument within a function call.
  • Fixed a bug that results in a false positive error when a TypeVar bound to a union of literals is used in the specialization of a TypeAlias whose TypeVar is bound to a wider union of literals.
  • Fixed bug in isinstance type narrowing logic that leads to incorrect narrowed type when the filter type (the second argument) and the test type (the first argument) are both type variables.

Behavior Changes:

  • Changed behavior of super() method call when self is annotated as a protocol class. This pattern is used for annotating mix-ins. In this case, pyright should not generate an error if the protocol's method isn't implemented.
  • Added code to deduplicate references returned by the textDocument/references LSP call.

Enhancements:

  • [contributed by @Seairth] Added multi-root workspaceFolder support in path variable expansion.
  • Improved logic for unpacked arguments that contain an "Unbound" type.
  • Improved handling of unreachability analysis for an "implied else" (an if/elif chain that is missing a final "else" clause).
  • Added check for an attempt to override a field in a named tuple within a subclass.
  • Added check for an attempt to delete a named tuple entry.
  • Added check for use of TypedDict or NamedTuple as second argument to isinstance call, which isn't allowed.
  • Added check for out-of-bound index accesses for named tuple instances.
  • Improved misleading diagnostic message when attempting to call a special type form.
  • Updated typeshed stubs to the latest version.
pyright - Published 1.1.349

Published by github-actions[bot] 9 months ago

Bug Fixes:

  • Fixed default for reportImplicitStringConcatenation in schema file.
  • Fixed a bug that resulted in an incorrect type evaluation for a union type used as a runtime expression. The type should be UnionType, not type[UnionType].
  • Fixed regression that resulted in a false positive error when calling an abstract method on an abstract class that passes through the constraint solver (e.g. a generic decorator).
  • Fixed a bug that results in a false positive when using a TypeVarTuple to capture the parameters of a generic callable that includes one or more default argument values.
  • Fixed bug in tuple type compatibility logic that resulted in a false negative when dest type includes an upacked unbounded tuple plus additional entries.
  • Fixed bug in tuple type compatibility logic that resulted in a false positive when dest type is tuple[Any, ...].
  • Fixed a bug that results in a false negative when the literal typing.Any is passed to a function that accepts a type[T]. Any is a special form and should not be compatible with type.
  • Fixed bug that resulted in incorrect type evaluation when a TypeAliasType is used in a value expression.
  • Fixed a bug that resulted in incorrect type evaluation when calling a tuple constructor with bidirectional type inference and the value passed to the constructor is an Iterable[Any].
  • Fixed a bug that resulted in incorrect type narrowing for sequence patterns when the subject expression contains a tuple with an unbounded component.

Behavior Changes:

  • Removed name consistency match for functional form of Enum. After a discussion in the typing community, it was decided that name consistency checks in some cases were unnecessary and inappropriate for type checkers.
  • Changed the way pyright translates tuple[()] into a specialized Sequence. It used to translate it to Sequence[Any], but the typing spec now clarifies that it should be Sequence[Never].
  • Changed handling of tuple with multiple unpacked embedded tuples. Type spec now clarifies this is OK as long as there are not multiple unbounded embedded tuples.
  • Added special-case logic to handle __name__ and a few other instance variables defined in the type class so they are treated specially when accessed from a class instance.

Enhancements:

  • Added check for inappropriate use of Final in a value expression.
  • Added support for enum member aliases defined within an enum class.
  • Improved error messages for tuple type mismatches that involve tuples with indeterminate types.
  • Added check for the use of Annotated or a type alias defined with Annotated as the second argument to an isinstance or issubclass call. This produces an exception at runtime.
  • Added additional performance enhancements specifically for large unions of literal types.
pyright - Published 1.1.348

Published by github-actions[bot] 9 months ago

Breaking Changes:

Many pyright users have requested finer-grained control over diagnostics — especially for diagnostics that were previously lumped under the catch-all rule reportGeneralTypeIssues. I was hesitant to do this because it is a breaking change and could be disruptive for some pyright users. However, the time has come to make this change.

The list of new diagnostic rules includes:

  • reportAbstractUsage
  • reportArgumentType
  • reportAssertTypeFailure
  • reportAssignmentType
  • reportAttributeAccessIssue
  • reportCallIssue
  • reportInconsistentOverload
  • reportIndexIssue
  • reportInvalidTypeArguments
  • reportInvalidTypeForm
  • reportNoOverloadImplementation
  • reportOperatorIssue
  • reportPossiblyUnboundVariable
  • reportRedeclaration
  • reportReturnType
  • reportUnusedExcept

Refer to the configuration documentation for more details about each of these.

This is a breaking change for code bases that were previously overriding the diagnostic severity for reportGeneralTypeIssues in the config file, in file-level pyright comments or in # type: ignore or # pyright: ignore comments. You will need to update your configuration settings and comments to use the new diagnostic rule names.

Bug Fixes:

  • Fixed bug in pyright's "type printer" that resulted in an incorrect output when printing a specialized type alias parameterized by a TypeVarTuple that has a value that contains a tuple with an indeterminate length.
  • Fixed a bug that resulted in an incorrect type evaluation when a generator uses an await operator within the left-most for. This shouldn't result in an AsyncGenerator despite what the Python documentation indicates.
  • Fixed a bug in the isinstance type narrowing logic when type is filtered using a metaclass instance.
  • Fixed recent regression that resulted in a crash when using certain language server features with an absolute extraPaths value.
  • Fixed spec conformance issue with TypeVarTuple constraint solving. The spec indicates that if a TypeVarTuple is used multiple times in a callee's signature, the tuple must "match exactly".
  • Addressed a bug that led to a false positive (missing error) when a "bare" TypeVar is used as a base class in a class statement.
  • Fixed a bug that masked an error (false negative) under certain circumstances when evaluating a lambda.
  • Fixed a bug that resulted in a false positive error and incorrect type evaluation when an assignment expression (walrus operator) is used in a comprehension.
  • Changed diagnostic rule for the case where Callable is missing a second type argument. It should use reportMissingTypeArgument.
  • Fixed a bug that led to a false negative when an illegal form of tuple was used: tuple[*tuple[str], ...].

Behavior Changes:

  • Changed handling of tuple[Any, ...] so it is treated as though it's bidirectionally type compatible with all tuples regardless of length. This change is made in response to a clarification in the typing spec. It brings pyright in alignment with mypy's behavior in this regard.

Enhancements:

  • Added check for name mismatch for enum classes defined using the functional syntax.
  • Improved handling of custom Enum classes (those that derive from Enum or use EnumMeta).
  • Added special-case logic for enum classes that are invoked as though they are being constructed.
  • Added type enforcement for the _value_ type in an Enum class. Also added enforcement for custom __new__ and __init__ method signatures.
  • Improved handling of Annotated and other special forms when they are used in runtime value expressions rather than annotations.
  • Added error reporting for the situation where a generic instance variable is accessed through a class object.
  • Updated typeshed stubs to the latest version.
pyright - Published 1.1.347

Published by github-actions[bot] 9 months ago

This is a quick-turn release to fix a regression that affected 1.1.346.

Bug Fixes:

  • Fixed regression that caused JSON output of CLI to not follow the documented schema.

Enhancements:

  • Added support for Python 3.11 enum features: enum.member and enum.nonmember.
  • Added new language server setting pyright.disableTaggedHints to disable the use of diagnostics hints with tags. Some language server clients do not display these tagged hints in the intended manner and instead treat them as regular diagnostics.
  • Changed all diagnostics (other than syntax errors and a few special informations) to have an associated diagnostic rule. Previously, some diagnostics had no associated rule.
  • Added support for @no_type_check decorator.
pyright - Published 1.1.346

Published by github-actions[bot] 9 months ago

Bug Fixes:

  • Added code to properly print a f-string expression in pyright's "expression printer". This affected stub generation if an f-string was used (e.g. in call to a decorator).
  • Fixed a bug that resulted in a false positive error when using a bound TypeVar in an except statement.
  • Fixed a bug that led to a false negative when using a non-data protocol class in a tuple within an issubclass check.
  • Fixed a bug that resulted in incorrect inference of an async generator expression if an await keyword was used in a for iterator expression.
  • Fixed a bug that resulted in an incorrect type evaluation for a sliced tuple if the end of the slice is the same as the tuple length (off-by-one error).
  • Fixed recent regression that results in a false positive error when an unpack operator is used in an Annotated type annotation.
  • Fixed false negative when a special form is assigned to a value declared as type[T] or when instantiated.
  • Added support for generic type alias specialization when the type alias includes an unpacked TypeVarTuple and the specialization list includes an unpacked unbounded tuple.
  • Fixed bug that led to incorrect protocol matching for class objects.
  • Fixed recent regression whereby a type created with NewType was no longer allowed as an argument for another NewType.
  • Fixed a bug that resulted in an incorrect implied specialization of a generic type alias that is parameterized by a TypeVarTuple. The implied type argument should be *tuple[Unknown, ...] in this case.
  • Fixed a bug in class pattern matching logic that incorrectly narrows types when using a str() class pattern and a LiteralString subject.
  • Fixed bug that caused "final method override" diagnostic to have no associated diagnostic rule.
  • Fixed a bug that resulted in incorrect variance inference for protocols (and for PEP inferred-variance TypeVars in PEP 695) when a self or cls parameter is explicitly annotated with a type that includes the type parameter.
  • Fixed a bug that resulted in a false positive when a contravariant TypeVar was used in a return type in a non-method.

Behavior Changes:

  • Changed the way pyright identifies an "unimplemented protocol method" within a stub file. It now looks at whether the method is decorated with @abstractmethod. Previously, it assumed all such methods were potentially implemented.
  • Changed error reporting for non-protocol classes that derive from a protocol but don't implement all of the unimplemented symbols in the protocol. Previously, pyright reported the error on the class declaration. Now, it reports it at instantiation time. This is more consistent with what other type checkers do.

Enhancements:

  • Updated typeshed to the latest version.
  • Added provisional support for proposed extension to typeshed's VERSION mechanism (https://github.com/python/typeshed/issues/11260).
  • Added support for + unary operator in Literal int type annotations. The typing spec was recently amended to allow this.
  • Improved handling of special forms defined in the typing module so they are treated correctly when used as runtime objects.
pyright - Published 1.1.345

Published by github-actions[bot] 10 months ago

Bug Fixes:

  • Fixed bug that led to false negative when a list expression was used within the first type argument of an Annotated type expression.
  • Added a missing error condition for a non-method function that is marked @final.
  • Fixed crash related to a regression introduced with recent internal URI tracking.
  • Fixed false negative for a TypeVarTuple constructor call that includes value constraints.
  • Fixed a bug that led to an incorrect type evaluation for an explicitly-specialized class parameterized with a ParamSpec.
  • Fixed bug that resulted in incorrect type evaluation when a PEP-695 TypeVar is shadowed by an identifier of the same name within an inner scope.
  • Added missing check for inconsistent use of @final in an overloaded function. Added missing check for override of an overloaded method marked @final.
  • Fixed bug in protocol matching logic to reject a protocol match if a variable is a ClassVar in the protocol but not in the concrete class (or vice versa).
  • Fixed bug that leads to a false positive when a generic property is defined within a protocol.
  • Fixed a bug that led to incorrect type evaluation when a constrained TypeVar includes literal types as constraints.
  • Added missing check for the specialization of a generic type alias that includes a TypeVarTuple plus two or more TypeVars.
  • Fixed a bug that resulted in a false negative when specializing a generic type alias parameterized by a regular TypeVar with an unpacked tuple.
  • Added missing error for an illegal unpacked argument in type argument list.
  • Fixed a bug that led to a duplicate error message when defining a class-scoped type alias.

Enhancements:

  • Improved error message for protocol classes that derive from non-protocol classes.
  • Improved error reporting for incompatible overrides.
  • Added code to report when the Concatentate special form is used in an illegal context.
  • Added support for constants for field names in NamedTuple call.
  • Improved evaluation logic for tuple slices. It now works in cases where the tuple includes unbounded entries or unpacked TypeVarTuples.
  • Improved type analysis performance in certain cases involving complex code flow graphs and "truthy" conditional statements.
  • Added check for a call to an unimplemented method in a protocol from a base class that explicitly calls it.
  • Implemented small performance improvement by not generating error messages during protocol TypeVar variance validation.
  • Added check for data protocols used in an issubclass call. PEP 544 indicates that this isn't allowed.
  • Added check for "unsafe overlaps" for a runtime-checkable protocol when used in an issubclass or isinstance check.

Behavior Changes:

  • Changed CLI to sort diagnostics by location within a file.
  • Removed support for Union[*Ts] and Union[*tuple[...]]. This functionality was included in an early draft of PEP 646 but was dropped in the final spec. The functionality can still be used in pyright if useExperimentalFeatures is set to true, but it will likely be removed entirely in the future.
pyright - Published 1.1.344

Published by github-actions[bot] 10 months ago

Bug Fixes:

  • Fixed bug that caused "go to definition" and semantic rename to not work for forward-declared symbols referenced in a "type" type alias definition.
  • Fixed bug in parser that resulted in an incorrect syntax error when certain expression forms were used with the type statement to define a type alias.
  • Fixed a bug that resulted in a false negative when attempting to access valid attributes from a type alias created via a call to the TypeAliasType constructor.
  • Fixed a bug that led to an incorrect type evaluation when explicitly specializing a generic class or type alias with a ParamSpec.
  • Fixed a bug that led to a false positive "not awaitable" error if the __await__ method return type was Unknown.
  • Fixed a bug that results in a false negative when the TypeAliasType constructor is called with an expression that refers to a traditional TypeVar.
  • Fixed a bug that leads to a false negative when validating type compatibility between two callables and the source has a position-only parameter corresponding to a non-position-only parameter in the dest.
  • Fixed bug in code flow analysis that resulted in an incorrect type evaluation when a "NoReturn" call is made within a code block protected by an exception-suppressing context manager.

Behavior Changes:

  • Added LSP exemption for __post_init__ method.
  • Improved overload overlap logic to detect partial overlaps when parameter types include unions that intersect.

Enhancements:

  • Improved logic that determines whether the expression used for a type statement or a call to TypeAliasType is a valid type expression.
  • Added additional checks for invalid NewType calls.
  • Improved detection of invalid type alias expressions for implicit (traditional) type aliases.
  • Improved error reporting for with statement when __enter__ or __aenter__ is present but cannot be bound.
pyright - Published 1.1.343

Published by github-actions[bot] 10 months ago

Bug Fixes:

  • Fixed bug that resulted in crash when using language server APIs in certain circumstances.
  • Fixed bug that resulted in incorrect type evaluation of a variable within a loop under certain conditions.
  • Fixed a bug in the function type assignment logic that leads to a false positive under certain circumstances involving a ParamSpec in an overload with a callback that includes a positional-only parameter separator.
  • Fixed a bug that leads to a false negative when Self is used within a class definition statement. PEP 637 explicitly rejects this usage of Self.
  • Fixed a bug that leads to a false negative when Self is used within a metaclass. PEP 637 explicitly rejects this usage of Self.

Enhancements:

  • Eliminated some unnecessary work when determining the effective type of a symbol that doesn't have a declared type. When evaluated in the context of a particular usage, it's unnecessary to evaluate any assignments within the same execution scope.
  • Add error checking for illegal use of unary, binary, or ternary operators within a type annotation.
  • Added detection of invalid keyword arguments in TypedDict class definition when using the normal class syntax.
  • Added detection of a call to TypedDict alternative syntax form that assigns the resulting class to a variable whose name doesn't match the name specified in the TypedDict call.
  • Added check for the use of a TypedDict class in an isinstance or issubclass call. These generate a runtime exception.