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.322

Published by github-actions[bot] about 1 year ago

This is a hot fix release to address a regression in 1.1.321.

Bug Fix: Fixed recent regression that led to a false positive when assigning a union of types that use invariant type parameters to a protocol that uses a covariant type parameter. This fix was already incorporated into this week's preview release of pylance (v2023.8.21), so it shouldn't affect pylance users.

Bug Fix: Fixed a bug that led to a spurious "Unknown" type when an assignment to a variable with a type annotation was used within a loop.

Bug Fix: Fixed false positive error when an empty tuple was used in an except statement.

pyright - Published 1.1.321

Published by github-actions[bot] about 1 year ago

Behavior Change (from pylance): Import suggestions are filtered when py.typed is available based on whether the symbol is considered public or private.

Bug Fix: Fixed a bug that led to a false positive in certain cases where a ParamSpec captures an overloaded function signature.

Bug Fix: Fixed a bug that resulted in a type evaluation error when using bidirectional type inference with a non-generic protocol.

Bug Fix: Fixed a bug that resulted in an off-by-one error in an error message when reporting the index of a mismatched overload.

Bug Fix: Fixed a bug that resulted in a false positive reportIncompatibleMethodOverride diagnostic when the base method used a double underscore to indicate position-only parameters but the override used the newer / separator.

Bug Fix: Revert "Fixed a bug that led to a false negative when determining whether two base classes that are combined using multiple inheritance implement the same method in an incompatible way. The bug caused the check to be skipped if the child class also implemented the same method as the two base classes.

Bug Fix: Fixed a bug that resulted in an incorrect hover type (and inlay hint) for the inferred return type of an async function or method.

Performance: Addressed a performance regression introduced in 1.1.314 due to a switch from ts-loader to esbuild-loader in our build pipeline. This change resulted in a 7-9% performance degradation, so I'm reverting it for now.

Enhancement: Added check for improper use of a type alias defined using the type statement introduced in PEP 695.

Bug Fix: Fixed bug that led to a false positive error in certain cases when using bidirectional type inference when the expected type includes a protocol that is specialized with a literal type argument.

Bug Fix: Fixed a bug that led to incorrect type narrowing on assignment in certain cases where the declared type includes a type argument with an Any and the assigned type does not.

pyright - Published 1.1.320

Published by github-actions[bot] about 1 year ago

Bug Fix: Reverted new version of chalk library. The newer version is not compatible with node v12.

Bug Fix: Fixed a bug that resulted in a false positive error when attempting to assign a TypeVar T that has a bound of type to an expression type[S].

Enhancement: Added a new configuration options flag called enableExperimentalFeatures that controls whether certain experimental features are enabled. Currently there are three features under this flag: StrictTypeGuard, ReadOnly fields for typed dicts, and inlined TypedDict definitions.

Enhancement: Removed support for experimental StrictTypeGuard and replaced it with an experimental variant of TypeGuard that applies strict semantics if certain conditions are met.

Bug Fix: Fixed a bug that led to incorrect variance inference when a value annotated with a class-scoped TypeVar was assigned to an instance variable.

Behavior Change: Updated heuristics for how to handle custom metaclass __call__ methods based on feedback. Previously, if a metaclass __call__ method was present, pyright assumed that __new__ and __init__ may not be called, so it ignored them. The new heuristic assumes that if the metaclass __call__ returns a type that is consistent with the expected return type of type.__call__ that it is probably mirroring the behavior of type.__call__ and calling the class' __new__ and __init__ methods.

Behavior Change: Changed auto-variance algorithm to exempt class and instance variables that are named as protected or private.

Bug Fix: Fixed a regression that caused class decorators of generic classes to no longer be specializable.

Bug Fix: Fixed a bug that resulted in an apparent hang within the type printing logic. This was triggered by a pathological case involving a deeply recursive type.

Behavior Change: Modified type inference logic so methods that raise an exception whose type derives from NotImplementedError is not inferred to return NoReturn. Previously, only NotImplementedError was exempted, not subclasses.

Behavior Change: Removed old code that looks for a typeshed override in the standard python search paths. This works around an issue with the inject library, which installs a bogus typeshed directory into site-packages.

Bug Fix: Fixed a bug that results in unsolved type variables in a call return if the target function's return type is a callable that has type variables that are scoped to that callable.

Bug Fix: Fixed a bug that resulted in incorrect type evaluation when a generic function that returns a callable is passed itself as an argument and the resulting callable is then called and passed that same function as an argument.

Bug Fix: Fixed a bug in the command-line version of pyright where it did not enable "auto search paths", so it didn't automatically add "src" as an extra path.

Bug Fix: Fixed a bug that led to a false negative when determining whether two base classes that are combined using multiple inheritance implement the same method in an incompatible way. The bug caused the check to be skipped if the child class also implemented the same method as the two base classes.

Bug Fix: Fixed a bug that resulted in a false positive error when using an unpack operator within a call to an overloaded function.

Bug Fix: Fixed a bug that resulted in a false positive error when a captured variable within an inner scope (function or lambda) is imported from another module using an import statement that comes after the function or lambda.

Bug Fix: Fixed bug that led to incorrect type evaluation when accessing the name attribute on an enum.

pyright - Published 1.1.319

Published by github-actions[bot] about 1 year ago

Bug Fix: Fixed a bug that results in a crash when attempting to use a member access expression where the LHS is a TypeVarTuple.

Bug Fix: Fixed a bug that led to a false negative when analyzing code with an async context manager that swallows exceptions.

Enhancement: Improved error messages for situations where a call expression targets an overloaded function or method and there are no matches. Added some heuristics to pick the "best" overload function for the error message. Previously, pyright used the last overload, but this sometimes led to confusing errors.

Enhancement: Added support for the X is C and X is not C type guard pattern (where C is a class).

Bug Fix: Fixed an issue in type evaluation of call expressions where the callable subexpression evaluates to a union, and the callable subtypes have different signatures. Pyright was previously caching the types from the first subtype, so it didn't re-evaluate using the second subtype (which may require bidirectional type inference).

Bug Fix: Fixed bug in hover text where it was not producing the correct text output for an instantiable callable.

Enhancement: Added detection and reporting of illegal use of type[Callable] within a type annotation.

Bug Fix: Fixed a bug that resulted in a false positive error when bidirectional type inference was used with a class that defines a __new__ method within a generic class that returns an instance of the class whose type arguments do not match the type parameters.

Bug Fix: Fixed an inconsistency in reporting of unbound variables when the variable is captured by an inner scope. The new behavior correctly identifies unbound (or potentially unbound) variables in cases where the captured variable is narrowed. This happens when there are no assignments to the variable after it is captured.

Bug Fix: Fixed a bug that led to a false positive when a constrained type variable was used as a type argument in an annotation for an argument passed to a method that's bound to the same type variable.

Bug Fix: Improved robustness of handling of circular dependencies for class evaluations.

Enhancement: Enhanced support for functools.partial so it supports classes (constructors) when passed as the first argument.

Bug Fix: Fixed a bug that led to a false positive error when using bidirectional type inference for a dictionary expression when the expected type is a protocol.

Enhancement: Updated typeshed stubs to the latest version.

Bug Fix: Fixed a bug that led to a hang and eventual crash (due to memory exhaustion) under certain circumstances where a function returns a generic Callable whose type parameters are not used in the input parameters for the function.

Bug Fix: Modified the heuristics used for narrowing on assignment when the assigned type contains an Any. If the target's declared type does not contain Any, the assignment shouldn't produce an Any within the resulting type.

Enhancement: Added support within the constraint solver for higher-order functions that accept a callable parameterized with a ParamSpec where the passed callable is generic.

Bug Fix: Fixed a bug that resulted in the incorrect inferred variance for a type variable used within a frozen dataclass.

Bug Fix: Fixed a theoretical bug in the code that detects unique type signatures. It wasn't correctly handling constructor methods.

Bug Fix: Added support for type narrowing of a class pattern when the specified class is type() or a subtype thereof and the subject contains a type[X] whose metaclass potentially matches the pattern.

pyright - Published 1.1.318

Published by github-actions[bot] over 1 year ago

Performance: Added code to handle pathological case in unannotated code that assigns values to the same variable hundreds of times with different types.

Bug Fix: Fixed a recent regression that resulted in unsolved type arguments when a "bare" generic class (like dict) is passed as an argument to a function that accepts a type[T].

Bug Fix: Fixed a bug in type narrowing for pattern matching in the negative (fall-through) case when the subject type contains an Any.

Enhancement: Added additional special-case handling for __init_subclass__ and __class_getitem__ to treat them as implicit class methods even if they are not declared using a def statement.

Bug Fix: Fixed bugs that resulted in incorrect or incomplete types when narrowing for sequence patterns in the negative case and the subject expression is a super-type of Sequence (such as object or Reversible).

Behavior Change: Modified is None type guard logic to eliminate Any or Unknown in the positive narrowing case.

Bug Fix: Fixed bug that resulted in a false positive reportOverlappingOverload error when overload contained the use of a constrained TypeVar.

Bug Fix (thanks to @ adpauls for contribution): Add fsevents as optional dependency to public package. This should improve file watcher behavior for large projects on MacOS.

Enhancement: Improved the error message for incompatible type arguments. Many users are confused about variance (in particular invariant type parameters). This change should help eliminate some of that confusion.

Bug Fix: Fixed a bug that resulted in a false negative when assigning a T | None type to object | None in an invariant context. This same bug led to issues with the validation of TypeVar variance within a Protocol.

Bug Fix: Fixed recent regression that resulted in a false positive error when using bidirectional type inference for an assignment to a class-scoped variable where the annotated type is a descriptor.

Enhancement: Improved checks for illegal use of a variable within a type expression. Added enforcement of these same rules for the first argument to a cast call.

Behavior Change: Removed the requirement that a TypedDict be marked @final for it to be considered for type narrowing as part of a S in D type guard pattern. This requirement wasn't sound because TypedDict is a structural type (i.e. a protocol), so @final doesn't have any real meaning.

Enhancement: Updated typeshed stubs to the latest version.

Bug Fix: Fixed bug that caused an error to go undetected when the LHS of a call expression is a union that includes an abstract static or class method.

Bug Fix: Fixed a bug that resulted in incorrect evaluation of a type alias defined with typing.TypeAlias and consisting of a single (naked) type variable.

Bug Fix: Fixed a bug that resulted in a false positive when an expression of type type[Self] was used as the base type for a member access expression that was then used to call an instance method on that class.

Bug Fix: Fixed a bug that led to a false negative when determining type compatibility between two unions in an invariant context.

Bug Fix: Fixed bug that resulted in the incorrect variance inference of an "auto variance" type parameter (as introduced in PEP 695).

pyright - Published 1.1.317

Published by github-actions[bot] over 1 year ago

Bug Fix: Fixed a regression that caused a false positive when comparing type compatibility between two Callable types that involve ParamSpecs.

Behavior Change: Changed '-' command-line feature to support multi-line input.

Enhancement: Added special-case support for enum fields that are assigned using an unpacked tuple operation.

Bug Fix: Fixed bug that resulted in false positive error when calling the same generic function with a ParamSpec multiple times as separate arguments within a call expression.

Bug Fix: Fixed another ParamSpec-related issue.

Enhancement: Extended support for TypedDict discrimination by literal field so it supports == and != with values that are unions of literal types.

Bug Fix: Fixed a bug that resulted in incorrect hover results for identifiers used as keys or values within a dictionary expression.

Bug Fix: Fixed recent regression in the synthesized TypedDict get method, which resulted in a false positive error when using strict mode.

Enhancement: Removed limitation that files specified on the command line or in "include" directives end in ".py" or ".pyi".

Bug Fix: Fixed a bug that results in incorrect type evaluation for a higher-order function involving a ParamSpec.

Behavior Change: Modified diagnostic checks for list, dictionary, and tuple literal expressions within annotation expressions so they are emitted as part of the reportGeneralTypeIssue diagnostic rule rather than unconditionally.

Bug Fix: Fixed bug that led to a confusing hover type for the return result of an async generator function.

Enhancement: Added support for deferred annotation evaluation for Annotated type arguments beyond the first one.

Bug Fix: Improved assignment mismatch errors to better handle the case where the two types have the same short name but different fully-qualified names. In this case, the types are now expanded to avoid confusion.

Bug Fix: Fixed incorrect type mismatch error messages within constraint solver logic. The source and destination types were swapped, which led to confusing messages.

Performance: Improved protocol type cache for improved type analysis performance in code bases that make heavy use of protocols.

Enhancement: Added detection of errors when a namedtuple definition includes a language keyword. Also added minimal support for the rename parameter to the namedtuple function.

Enhancement: Updated typeshed stubs to the latest version.

pyright - Published 1.1.316

Published by github-actions[bot] over 1 year ago

Note: This will be the last version of pyright published for the next couple of weeks. Responses to bug reports and questions may also be delayed over the next few weeks.

Bug Fix: Fixed a bug in the new - command-line feature. This addresses

Bug Fix: Fixed another instance of a false positive reportMissingTypeArgument error when a generic class is passed as the second argument to isinstance.

Enhancement: Added support for bidirectional type inference when using a dictionary expansion and a dictionary literal expression for an argument corresponding to an unpacked TypedDict **kwargs parameter.

Bug Fix: Fixed bug that resulted in incorrect type evaluation when a generic callback protocol was invoked in a nested manner.

Bug Fix: Fixed a bug that resulted in a false positive when passing a class to the defaultdict constructor. If an unspecialized class type is used as a upper or lower constraint within the constraint solver, we now use default type arguments (typically Unknown) rather than leaving these type arguments unspecified.

Behavior Change: Modified the signature of the synthesized get method for TypedDict classes so it more closely matches the signature (and therefore the behavior) of the get method in dict.

Bug Fix: Fixed regression that caused crash within certain doubly-nested loops.

Bug Fix: Fixed a bug that results in a false positive error when attempting to assign a class to a Callable type when the class is generic and the constructor includes class-scoped type variables in its parameter annotations.

Bug Fix: Fixed a bug that led to a false negative when a generic class with called its own constructor using its own type parameters as type arguments.

pyright - Published 1.1.315

Published by github-actions[bot] over 1 year ago

Bug Fix: Fixed a regression that caused a false positive reportMissingTypeArgument diagnostic when using a generic type in conjunction with the | union operator in the second argument to an isinstance or issubclass call.

Bug Fix: Modified protocol matching and the constraint solver to handle an edge case where a partially-solved type variable with a solution of Any are provided by other argument types in a call.

Bug Fix: Fixed a bug that leads to a false positive error in the reportIncompatibleMethodOverride check when a child class is overriding an overloaded method in the base class and one or more of the overloads doesn't apply because the self or cls parameter is explicitly annotated in a way that's not applicable to the child class.

Bug Fix: Fixed a bug in type evaluation of the two-argument form of the super call. There were situations where the incorrect MRO class was used.

Bug Fix: Fixed bug that led to false positive errors when performing protocol matching in certain circumstances.

Bug Fix: Fixed a bug that led to a false positive when passing unpacked lists or dictionaries to a constructor for a class that doesn't provide its own constructor and falls back to the object constructor.

Bug Fix: Changed parameter type inference logic to avoid inferring the type of an unannotated parameter with a default value consisting of a lambda.

Bug Fix: Fixed a regression that caused an incorrect type evaluation of a function that returns a callable with a ParamSpec that does not appear outside of the return type annotation. A previous fix didn't correctly handle the case that involved a class parameterized with a ParamSpec.

Bug Fix: Fixed a false negative where an unpacked dictionary argument was not validated against the **kwargs parameter type.

Bug Fix: Fixed several subtle bugs in the overload matching algorithm in the case where Any or Unknown arguments are present.

Enhancement: Improved the heuristic used to determine which subtypes of a union within an "expected type" should be used for bidirectional type inference.

Bug Fix: Fixed bug that led to an incorrect type evaluation for nested call expressions where an inner call expression used a ParamSpec.

Bug Fix: Fixed false negative when a literal and non-literal are assigned to the same TypeVar in an invariant context.

Behavior Change: Changed auto-variance algorithm to ignore __new__ and __init__ methods for purposes of calculating the variance of a TypeVar. This mirrors the behavior of mypy.

Bug Fix: Fixed a bug that led to incorrect type evaluation when passing a generic class (with a constructor that includes class-scoped TypeVars) as an argument for a callable parameter. The class was being specialized prematurely (with type arguments set to Unknown) before the constraint solver was able to solve the higher-order function's type variables.

Bug Fix: Fixed a false positive error arising from the use of a binary expression for a base class in a class declaration statement.

Enhancement: Improved hover text to display the calculated variance for a PEP 695-style class-scoped type variable when the user hovers over the type parameter in the type param list.

Bug Fix: Fixed a bug that led to a false positive error under certain circumstances when a literal type argument was used in conjunction with a protocol that used a covariant type parameter and an implementation of that protocol that used an invariant type parameter.

Behavior Change: Changed type printer (the component that renders types into text) to use the lowercase type[x] instead of Type[x]. It has now been four years since PEP 585 deprecated the use of the upper-case version, so most developers should be getting comfortable with the lowercase version at this point.

Enhancement: Improved reportUnnecessaryCast so it works with types other than class instances.

Enhancement: Improved type inference for lambdas in the case where a parameter includes a default value and the expected type doesn't include that parameter.

Bug Fix: Fixed bug in code flow engine that led to incorrect type evaluation of a variable in a nested loop.

Bug Fix: Fixed bug that resulted in a false positive error when defining a new type alias using the TypeAliasType constructor that defines no new type parameters but references an outer-scoped type parameter in the type alias definition.

Enhancement: Enhanced command-line version of pyright to allow file or directory names to be passed via stdin if - option is used in the command line.

Behavior Change: Changed behavior of non-ClassVar variables within a protocol definition. Previously, an error was reported when such variables were accessed from the class (as opposed to an instance of the class). Mypy (which was the reference implementation for PEP 544) does not report an error here.

Bug Fix: Fixed a bug that caused incorrect type inference for parameters in unannotated methods within child classes who derive from a generic parent class.

Enhancement: Updated typeshed stubs to the latest version.

Bug Fix: Fixed a bug that caused an incorrect false positive error for an assert_type call involving a Callable[[], X] type. Pyright was generating a signature with a positional-only separator in this case.

Enhancement (contributed by debonte): Added support for PEP 712's new attribute assignment conversion.

Performance: Fixed a bug in type caching mechanism that could have resulted in poor performance in certain circumstances.

Performance: Added low-level caching mechanism for converting between instance and instantiation types. This should reduce memory usage in some circumstances.

Enhancement: Enhanced the isinstance type narrowing logic so it filters types based on the number of entries in a tuple if the type derives from a tuple.

pyright - Published 1.1.314

Published by github-actions[bot] over 1 year ago

Enhancement: Updated typeshed stubs to the latest version. This update includes some substantive changes to stdlib protocols and classes related to buffers. These changes will result in some compatibility issues for some libraries. For more details about the motivation for these changes, refer to PEP 688.

Regression Tests: Upgraded pyright’s CI process to include the execution of mypy_primer, a tool that was written by @hauntsaninja for mypy and typeshed to catch regressions. He extended the tool to support pyright. If you are a repo owner who uses pyright in your CI and would like us to include your project in pyright’s CI (to understand and prevent regressions that could affect your project), let us know.

Bug Fix: Fixed bug that resulted in a false negative when using the reportMissingTypeArgument check when defining an old-style type alias. This same bug resulted in inconsistent behavior between Union and |, which should be equivalent.

Bug Fix: Fixed a bug in the typeshed VERSIONS exclusions. It was falling back on the VERSIONS file in the packaged typeshed rather than using the custom typeshed path specified in the configuration or command line.

Bug Fix: Fixed a bug that led to a false negative when passing an unpacked tuple of length one to a function that requires more (or fewer) than one positional argument.

Performance: Reverted a recent internal refactoring because it resulted in increased peak memory usage in some cases.

Bug Fix: Fixed false positive error when using a *args: P.args as the first parameter in a method.

Bug Fix: Improved the protocol matching logic so it honors partially-solved type variables whose values are provided by other argument types in a call.

Bug Fix: Fixed a bug that led to infinite analysis time and heap exhaustion when analyzing an overloaded function that includes a ParamSpec that uses itself as an argument.

Bug Fix: Fixed a bug that led to a false positive reportIncompatibleMethodOverride error for overloaded method overrides in cases where the overloads are differentiated based on explicit types for the self or cls parameter.

Bug Fix: Fixed a regression that caused an incorrect type evaluation of a function that returns a callable with a ParamSpec that does not appear outside of the return type annotation.

pyright - Published 1.1.313

Published by github-actions[bot] over 1 year ago

This is a hot-fix release aiming to address a specific regression in pyright 1.1.312 reported here.

Bug Fix: Reverted latest typeshed updates that caused a regression related to buffer types.

pyright - Published 1.1.312

Published by github-actions[bot] over 1 year ago

Bug Fix: Fixed a bug that results in a false positive when calling a generic function that has a declared return type of a tuple and the call has an expected type (bidirectional type inference).

Enhancement: Enhanced reportIncompatibleMethodOverride diagnostic check to support cases where the overridden function is overloaded. Attempted to duplicate the same logic that's in mypy for compatibility.

Bug Fix: Fixed a bug that resulted in a false positive in certain obscure cases involving callables with parameters that are typed using TypeVarTuples.

Bug Fix: Fixed a bug that led to false positive errors when a generic function was called in a nested manner (i.e. invoked as in an argument expression).

Bug Fix: Fixed a bug that resulted in the incorrect return type inference for an async function that has no type annotations.

Bug Fix: Fixed bug that resulted in a false positive error when using a nested Literal that includes None.

Bug Fix: Fixed a bug that led to extremely long (effectively infinite) evaluation times when a generic function was passed as an argument to itself.

Behavior Change: Changed the matching of an unpacked dictionary passed as an argument to a callable when keyword arguments are present and have default values. Previously, the types of all such parameters were not checked against the unpacked dict type (under the assumption that the default argument would satisfy the parameter in this case). The new behavior matches that of mypy and assumes that the unpacked dict may supply arguments for all otherwise-unmatched keyword parameters even if they have default argument values.

Enhancement: Added auto-exclude logic specifically for typeshed so stdlib stubs that are not "in scope" for the current python version are auto-excluded from the project. This applies only if the typeshedPath is set to ..

Bug Fix: Fixed issue that caused a false positive error in typeshed CI due to nondeterministic handling of circular dependency in ReprEnum class.

Bug Fix: Fixed a bug that led to a false positive error when validating the consistency of the return type of a generator function if the return type declaration was not specifically Generator or Iterable (or their async counterparts).

Bug Fix: Fixed a false negative type error involving a recursive type alias that includes a Sequence and a str (which is itself a recursive type involving Sequence).

Bug Fix: Fixed a bug that led to a false positive error when a call expression was used on the RHS of an "or" or "and" operator and the target callable involved an overload with a function-scoped TypeVar in the return type.

Bug Fix: Fixed a bug in the tokenizer that led to an incorrect error for an f-string that ends in a double backslash.

Bug Fix: Improved evaluation of nested calls that involve the same generic function or multiple uses of the same generic function as arguments to the same call. In these cases, the generic signatures need to be made unique so the type variables of each are treated as though they are independent.

Enhancement: Updated typeshed stubs to the latest version.

pyright - Published 1.1.311

Published by github-actions[bot] over 1 year ago

Bug Fix: Fixed regression in f-string tokenization that led to a false positive error when an escape character (backslash) is used with a carriage return or line feed within the non-expression part of an f-string.

Bug Fix: Fixed a bug that resulted in a crash in certain cases within the argument/parameter matching logic.

Bug Fix: Fixed recent regression that led to a false negative when using functools.partial with bidirectional type inference.

Bug Fix: Fixed a bug that led to (temporary) sporadic reportUnnecessaryTypeIgnoreComment errors.

Bug Fix: Fixed a recent regression that affected a function that returned a generic Callable that used type[T] rather than T in the type annotation.

Bug Fix: Fixed a recent regression that resulted in the incorrect evaluation of the value field for an Enum.

Bug Fix: Fixed a bug that led to an unsolved type variable within a union producing an Unknown type in some cases. This triggers false positive errors in strict mode.

Bug Fix: Fixed a bug that allowed unsolved type parameters to "leak" from a __new__ call in some cases.

Bug Fix: Fixed a bug that led to a false positive when a function-scoped ParamSpec was used within a constructor, and a lambda with no parameters is passed to the constructor as an argument.

Bug Fix: Fixed a bug that led to false positive errors for a constructor call used in conjunction with bidirectional type inference for a generic class that includes both a __new__ and an __init__ method.

Bug Fix: Fixed a bug that led to incorrect handling of # type: ignore comments if a file is type checked but then pyright runs low on memory and is forced to dispose of cached parse information. We now precompute the accumulated diagnostics while the cached parse information is available.

Bug Fix: Fixed a bug that led to a crash when running pyright --verifytypes numpy. A pathological case in the numpy code was causing an exponential explosion in the number of type variable signature contexts.

pyright - Published 1.1.310

Published by github-actions[bot] over 1 year ago

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. 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.

pyright - Published 1.1.309

Published by github-actions[bot] over 1 year ago

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.

pyright - Published 1.1.308

Published by github-actions[bot] over 1 year ago

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.

pyright - Published 1.1.307

Published by github-actions[bot] over 1 year ago

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.

pyright - Published 1.1.306

Published by github-actions[bot] over 1 year ago

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, 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.

pyright - Published 1.1.305

Published by github-actions[bot] over 1 year ago

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.

pyright - Published 1.1.304

Published by github-actions[bot] over 1 year ago

Bug Fix: Fixed recent regression that led to a false positive error when useLibraryCodeForTypes was false and an import of the form from a.b import c targeted a namespace package a.b that contains a traditional package c.

Bug Fix: Fixed bug that resulted in incorrect type narrowing for case statements that involved sequence patterns when the subject included a recursive type alias.

Enhancement: Added support for functools.partial when the provided function is overloaded.

Bug Fix: Fixed bug that resulted in a false positive when evaluating the types of nested generic function calls when bidirectional type inference is required.

Bug Fix: Fixed bug that resulted in an unresolved Unknown type in a doubly-nested loop when the value comes from a call to an overloaded function or magic method.

Enhancement: Improved type inference for enum values in an enum class created with the one-line form x = Enum("x", "a b c").

Bug Fix: Improved error handling for enum classes created with the one-line form x = Enum("x", "a b c"). The code now handles other whitespaces and commas and properly checks for format strings.

Enhancement: Added support for other functional Enum calls including a list of strings, a tuple of strings, a list of tuples, a tuple of tuples, and a map.

Enhancement: Added support for type evaluation of lambdas that are immediately called. The inferred types of the lambda's parameters must be inferred from the argument types in this case.

Bug Fix: Fixed recent regression that causes a false positive when a variable is assigned an expression of ... within a type stub file and strict type checking is enabled.

Bug Fix: Fixed a bug that leads to a false positive error when evaluating the type of a method that contains a function-scoped ParamSpec when the method is partially specialized through a binding operation.

Enhancement: Improved overload filtering for constructor calls when the class defines no __init__ but does define an overloaded __new__.

Enhancement: Added limited support for type narrowing of subexpressions of the subject expression for match statements. In particular, added support for discriminated TypedDicts and tuples that are discriminated on literals.

Enhancement: Enhanced type narrowing in the negative (not matched) case for sequence pattern matching when the subject is a tuple of known length. In cases where the pattern narrows one tuple entry in the positive case, we can eliminate that subtype in the negative case.

Enhancement: Enhanced type narrowing for pattern matching in cases where the subject is a tuple expression and one of the entries is a subexpression that is later used in a case statement block.

pyright - Published 1.1.303

Published by github-actions[bot] over 1 year ago

Behavior Change: This change may require changes to your configuration. Changed the default of the useLibraryCodeForTypes from false to true to bring pylance and pyright into alignment. Also deprecated the "--lib" command-line option, which was previously used to enable useLibraryCodeForTypes from the command line. If your project relies on the old default value, you will need to explicitly set useLibraryCodeForTypes to false in your project’s configuration file.

Behavior Change: Changed reportImportCycles so it is not on by default in "strict" type checking mode. It is highly opinionated and should be used only in cases where the developer opts into it.

Enhancement: Improved the synthesized __init__ method of a TypedDict class so it accepts another instance of the same TypedDict (or another TypedDict that is type compatible) as an argument. This makes pyright compatible with mypy in this regard.

Bug Fix: Added the ability for any callable to conform to a protocol that includes attributes and methods defined in the pseudo-class builtins.function.

Bug Fix: Fixed a bug that resulted in incorrect type evaluation when a partially-specialized generic method (with method-scoped type variables) is passed multiple times to a function that accepts generic callables.

Behavior Change: Reverted recent change that validated that explicitly-annotated self and cls in overloaded methods was a subtype of the class that contains them. This change made pyright consistent with mypy, but feedback from pyright users indicated that it was not desired. There are legitimate use cases for this in the overload case.

Bug Fix: Fixed bug that led to incorrect type narrowing for mapping patters in a case statement if the type included a recursive type alias.

Bug Fix: Fixed bug that potentially resulted in internally corrupted state when a class or def statement appears within a conditional block that is determined by the binder to be unreachable.

Bug Fix: Fixed a bug that resulted in a false positive error when assigning a function that has one or more tuple parameters to a generic callable that also accepts tuple parameters.

Bug Fix: Fixed a bug that led to a false positive error when combining a generic callback argument with a second argument that is an empty dict expression.

Bug Fix: Fixed bug in typePrinter that caused syntactically-incorrect output when using the "PythonSyntax" flag and passing a callable type that has a ParamSpec but no additional concatenated parameters.

Performance: Improved internal type caching mechanism used in cases where evaluation needs to be done speculatively (e.g. when evaluating argument expressions for an overloaded function). The previous code consumed significant memory and CPU cycles in certain circumstances.