Releases: microsoft/pyright
Published 1.1.379
Bug Fixes:
- Fixed a bug that results in confusing hover information for an attrs field that uses a converter.
- Fixed bug that results in incorrect type evaluation when assigning a recursive type alias to a tuple or list.
- Fixed a bug that can result in difficult-to-reproduce type evaluation errors when modifying code in your editor and using pyright as a language server.
- Fixed bug that results in the incorrect type when the
Callable
special form is used in a value expression.
Enhancements:
- Added check for concatenated bytes and str literals.
- Added provisional support for draft PEP 747 and the
TypeForm
special form. - Updated some diagnostic strings to refer to "type expression" rather than "type annotation" since they apply to some cases that don't involve annotations.
Published 1.1.378
Bug Fixes:
- Fixed bug that results in incorrect logging of the pythonVersion string.
- (from Pylance) Fixed issue that resulted in the incorrect pythonVersion when a pyproject.toml is present with a "[tool.pyright]" section.
- Fixed a bug that results in false negatives for errors in argument expressions used in a call to
functools.partial
in some cases. This same issue also causes symbols accessed in these arg expressions to not be marked as referenced. - Fixed bug that results in a crash in very specific circumstances that involve binding a method parameterized by a function-scoped ParamSpec.
- Fixed a bug that resulted in incorrect evaluation when converting a constructor to a callable and the constructed class has a metaclass with a
__call__
method whosecls
parameter is annotated withtype[T]
. - Fixed bug that results in a
reportIncompatibleMethodOverride
diagnostic being reported in the wrong location in some cases involving decorators. - Fixed a bug that results in a false negative when overloads overlap due to default values.
Behavior Changes:
- Changed the default value of the
disableBytesTypePromotions
setting fromfalse
totrue
. It has been over two years since PEP 688 was accepted, so it's time for us to stop treatingbytes
as an alias forbytes | bytearray | memoryview
. This is a breaking change and may require an update to the pyright configuration for some code bases.
Published 1.1.377
Bug Fixes:
- Fixed bug that results in a crash under certain circumstances when a ParamSpec without a scope is used illegally to specialize a class.
- Fixed a bug that results in a false positive error when assigning a
TypeGuard[T]
orTypeIs[T]
to a supertype ofbool
(likeint
). - Fixed a bug that leads to a crash when
--pythonversion
and--threads
CLI options are used together. - Fixed a bug that leads to incorrect type evaluation in certain specific conditions involving a function decorator with an return type inferred from an inner function parameterized by a ParamSpec.
- Fixed bug that results in a false positive error under very specific conditions involving a recursive type alias that is defined in terms of another type alias.
Enhancements:
- Changed type checking logic to retain a reference to default expressions in function signatures, including synthesized signatures (such as
__init__
methods in dataclasses). This allows the original default value expression to be printed in error messages and language server strings. - Updated typeshed stubs to the latest version.
- Added unreachable code reporting for case statements that are never matched based on type analysis.
Published 1.1.376
Bug Fixes:
- Fixed bug that results in a crash when an empty tuple is used to specialize a generic type alias parameterized by a ParamSpec.
- Fixed a bug that results in a false positive reportInconsistentOverload error when the implementation of the overload includes a decorator that changes the type of the implementation to a non-function type.
- Fixed bug that results in a false positive error when type argument for
Literal
doesn't follow type expression rules within a value expression context. - Fixed regression that resulted in a hang when determining whether an overload implementation with generics was compatible with its overloads.
- Fixed bug that results in a false negative
reportIncompatibleMethodOverride
when the child class method uses a type parameter that is scoped to the child class. - Fixed bug that produces signatures with extra (unnecessary) positional-only and keyword-only separators when using a TypedDict with zero fields.
- Improved consistency of parameter name restrictions for the
reportSelfClsParameterName
check. Previously, different rules were applied to__new__
and class methods within metaclasses. - Fixed a false positive error when solving type variables in a call that involves a lambda.
- Fixed bug that results in a confusing type in an error message when
isinstance
type narrowing between atype
and another type creates a subclass. - Fixed bug that leads to false positive error when a protocol has a read-only property a class has a Final variable.
- Fixed bug that leads to a hang under certain circumstances involving deeply-nested higher-order functions.
- Fixed bug that results in a confusing type in an error message when
isinstance
type narrowing between atype
and another type creates a subclass.
Enhancements:
- Enhanced argument-to-parameter matching logic to support dictionary unpacking where the dict key type is a union of literals.
Behavior Changes:
- Changed composition of settings that affect type checking behaviors. Previously, some LSP settings that affect type checking could override config files. Now, the config file always "wins". Command-line parameters passed to the CLI version of pyright win over both LSP settings and config files.
- Changed synthesized comparison methods (
__lt__
, etc.) for dataclasses whenorder=True
to useSelf
rather than an instance of the class. This is not only more consistent with other synthesized methods, but it also preserves covariance of type variables if the dataclass is frozen. - Changed behavior for protocols that have methods with method-scoped type variables. These are no longer treated as free type variables during protocol matching, so they can be used to support rank-2 polymorphism. This behavior is not currently dictated by the typing spec, but it is more consistent with mypy.
Published 1.1.375
Bug Fixes:
- Fixed bug that results in a false positive error when a covariant type variable that is scoped to a method is used in a parameter annotation.
- Fixed bug that leads to internal data structure corruption and subsequent false positive errors in certain cases involving unions of
Unknown
types that include type aliases. - Fixed bug in the
functools.partial
logic that results in incorrect handling of an unpacked TypedDict when used with a**kwargs
parameter. - Fixed bug that results in a false positive
reportUnsupportedDunderAll
warning when using the__all__.extend(x.__all__)
form and the list of entries inx
is empty. - Fixed bug in TypeVar auto-variance calculations for NamedTuples. Since NamedTuple variables are read-only, they should not cause a TypeVar to be invariant.
- Added subtyping support or
IntEnum
andStrEnum
members. These literal values are subtypes of the corresponding literalint
orstr
. - Fixed bug that results in a false positive error under certain circumstances when passing an overloaded function as an argument to a call.
- Fixed bug that caused first argument of
cast
method onmemoryview
object to be treated as a type expression. Pyright was confusing this method withtyping.cast
. - Fixed a bug that results in incorrect overload matching when one overload contains a zero-arity variant and another overload contains an
*args
(variadic) parameter. - Fixed a bug that results in incorrect type narrowing for truthy/falsy type guards consisting of an Enum member when the enum class derives from ReprEnum. In this case, the "magic" of the enum implementation forwards the
__bool__
call to the underlying value. - Fixed a bug that results in incorrect type narrowing when using
isinstance
with an instance of a generic class as the first argument and a concrete subclass as the filter type. - Fixed bug in type narrowing logic for value patterns, specifically when two enums with members of the same name are involved.
- Fixed bug that causes infinite recursion and memory exhaustion under certain circumstances involving recursive type aliases where the type alias is used as a type argument.
Enhancements:
- Updated typeshed stubs to the latest version.
- Added support for
bool
expansion toLiteral[True] | Literal[False]
during pattern matching when using value patterns.
Behavior Changes:
- Changed
disableLanguageServices
feature to apply to hover text as well as other language services. Previously, hover text was excluded. - Allow
Final
andClassVar
to be combined in both directions within a dataclass. Previously, theFinal
qualifier needed to be the outermost.
Published 1.1.374
Note: This week's release includes some major changes related to TypeVar constraint solving that have been in the works for a while. These changes simplify the code, make constraint solving behaviors more consistent, and eliminate a number of false positive errors that were reported over the past year. However, these code changes produce different constraint solving behaviors in some cases. These extensive code changes also come with the potential of regressions. I've done extensive analysis of the type checking outputs across over a hundred public code bases, but it's possible that I've missed something. Please report any new behavior that you think is a bug.
Bug Fixes:
- Fixed bug in logic that validates subtyping relationships between
TypeIs[T]
,TypeGuard[T]
andbool
when used in a return type of a callable. - Fixed bug that results in a crash if
Optional
is used with no subscript (i.e.Optional[]
). - Fixed bug in
isinstance
type narrowing if the second argument isobject
and the first argument is atype
instance. - Fixed a bug that results in a crash in certain conditions involving a corrupt builtins.pyi stub.
- Fixed recent regression that results in incorrect
isinstance
type narrowing when the filter class and the type are both protocols. - Fixed bug that results in a warning if the
self
parameter in an__init__
method is given an explicitSelf
annotation. - Fixed recent regression that results in a false positive error when evaluating certain nested constructor calls when used with bidirectional type inference.
- Fixed false positive error when iterator returns a class object from its
__iter__
method. - Fixed recent regression that results in a false positive error under certain circumstances when yield expression includes a call to a constructor.
- Fixed a bug that results in an incorrect "inconsistent overload" error when the overloads return
TypeIs
orTypeGuard
and the implementation returnsbool
. - Fixed a bug that results in incorrect type narrowing when tuples are used in conjunction with
TypeIs
. - Fixed a bug that can result in incorrect type evaluation when an
isinstance
type narrowing results in an intersection type. - Fixed bug that results in a false negative if a
__set__
descriptor method is marked deprecated and is implicitly accessed using an augmented assignment operator, as ina.x += 1
. - Fixed bug that can result in a false negative when a function return type is a TypeVar and the function falls through and implicitly returns a
None
. - Fixed bug that can result in a false positive when calling the constructor within a class that has unannotated
__init__
or__new__
method parameters. - Fixed bug that results in false positive error under certain circumstances when solving type variables that involve literal values.
- Fixed bug that results in a false positive when using a two-argument form of
super()
outside of a class.
Enhancements:
- Improved signature help for constructor calls. Replaced old heuristics that displayed either the
__init__
or__new__
signature with a mechanism that uses the recently-ratified typing spec algorithm for converting a constructor into a callable. This is prompted in part by this discussion. - Added error check for an enum attribute with a "naked"
Final
attribute. This should be considered invalid. - Added a new configuration option
enableReachabilityAnalysis
. It is off by default whentypeCheckingMode
is "off" but otherwise on by default. When disabled, it causes pyright not to identify code blocks that are determined to be unreachable via type analysis. Code blocks that are determined to be unreachable via non-type information are still displayed as such. - Enhanced type narrowing for sequence patterns to support tuple expansion when the subject is a tuple whose entries are union types.
- Added missing check for
Final
variable assigned in a loop. - Added support for
@deprecated
decorator on magic methods for unary and binary operations. - Added support for
@deprecated
on__bool__
magic method used bynot
operator. - Added support for
@deprecated
on__new__
methods used implicitly during a class constructor call.
Other Changes:
- Changed evaluation behavior for TypeVar bounds, constraints, and defaults to enforce type expression evaluation rules, consistent with the typing spec.
- Eliminated error condition when using a subscript expression for a generic class that does not conform to type expression rules (e.g.
list[1 + 2]
) if the expression is a value expression. - Modified heuristics in
T is None
type narrowing logic to handle TypeVars with no bounds better. The previous logic was arguably correct, but it produced results that were unexpected by some users. - Adjusted the heuristics for constraint solving to favor solutions of type
T
overtype[T
]` when both are valid.
Published 1.1.373
Bug Fixes:
- Fixed regression that results in a false positive when an
Annotated
type is used in a type argument within a specialized type on the LHS of a call expression, such aslist[Annotated[int, ""]]()
. - Fixed a bug that results in incorrect type evaluation in certain edge cases involving bidirectional type inference with TypeVarTuples.
- Fixed a bug that results in a false positive error when using bidirectional type inference for a call expression where the expected type is a union.
- Added the distinction between "external" versus "internal" type variable scopes. This is important for generic class implementations that call their own constructors.
- Fixed a bug that results in incorrect type narrowing when using
TypeIs
form when the return type of the type guard function is a specialized generic class. - Fixed bug that results in a false positive "overlapping overload" diagnostic when the later overload includes a callback function with a TypeVar in a parameter type.
- Fixed bug that resulted in an infinite loop when evaluating a call that passes the same call as an argument. Simplified tracking of unique signatures within the code.
- Fixed a bug that can cause a hang during type analysis for complex code with loops. There are rare circumstances that can cause types not to converge due to symbol dependencies and unstable overload resolution. This change adds a hard limit on the number of attempts to converge types in a loop before giving up.
- Fixed a bug that results in false negatives in certain cases involving bidirectional type inference for constructor calls.
- Fixed issues with the
reportInconsistentConstructor
. It produced false negatives in some cases and produced bad error messages in other cases. - Fixed bug that results in a crash if an explicit specialization of a class parameterized by a ParamSpec has zero type arguments. This is a syntax error, but it shouldn't cause the type evaluator to crash.
Behavior Changes:
- Changed all diagnostic generated in the type evaluator to have a diagnostic rule associated with them so their severity is under user control.
- Changed internal behavior to retain type alias information when applying solved type variables for a type. This doesn't change type checking behaviors, but it changes language server output (e.g. hover text) in some cases. It can also affect diagnostic messages.
Enhancements:
- Added provisional support for draft PEP 736 (keyword argument shortcut syntax).
- Added check for class attribute type declarations that use method-bound type variables. These should be illegal.
- Improved type evaluation for tuples index expressions with negative subscripts and an entry with an indeterminate length.
- Made support for "converter" parameter in dataclass_transform fields non-experimental. This functionality has been approved by the typing council.
- Added support for bidirectional type inference for
__extra_types__
in a closed TypedDict. - Updated typeshed stubs to the latest version.
- Added support for auto-synthesized
__replace__
method in dataclass and namedtuple classes, a new feature in Python 3.13.
Published 1.1.372
Bug Fixes:
- Fixed bug that can result in incorrect evaluation of a traditional (pre-PEP 695) type alias the defines a union which is later used as the second argument to an
isinstance
orissubclass
call. - Fixed bug in type narrowing logic for sequence pattern matching when a "star" entry in the pattern captures a TypeVarTuple. The resulting type should be
Unknown
rather than the unpacked TypeVarTuple. - (from pylance) Fixed regression that broke CLI when used with poetry or other tools that depend on the working directory.
- Fixed a recent regression that results in a false positive when the fully-qualified form of
typing.Request
is used in an annotation expression. - Fixed a bug that results in false positive
reportInconsistentConstructor
errors if one or both of__init__
or__new__
are overloaded. - Fixed a bug that results in a false positive
reportOverlappingOverload
error in certain cases involvingParamSpec
andConcatenate
. - Fixed a bug that results in incorrect import resolution behaviors when a ".py" file and a directory have the same name, and the directory doesn't have a
__init__.py
file in it. In this case, the ".py" file should take precedence during imports. - Fixed inconsistent behavior when evaluating a binary expression with an
or
orand
operator when the LHS evaluates to a literalint
,str
,bytes
orbool
type. - Fixed bug that results in a false positive error under certain circumstances when a generator function with no type annotation contains a return value.
- Fixed bug that results in some circumstances in incorrect specialization of
type[T]
whenT
evaluates toAny
. - Fixed false positive error when using an overloaded
__init_subclass__
method under certain circumstances.
Enhancements:
- Added support for negative type narrowing (in the fall-through case) for a mapping pattern consisting of a single dictionary expand entry. This should match all mapping types, eliminating them in the fall-through case.
- Added support for class declarations within an enum class body -- both with and without
@member
and@nonmember
decorators. - Added "literal math" support for bitwise operators (left shift, right shift, logical or, logical and, logical xor, and invert).
- Improved the handling of bidirectional type inference for call expressions when the expected type comprises a union.
- Added "literal math" support for exponentiation operator.
- Improved performance of type analyzer an average of 12% by refactoring internal data structures and making key objects "monomorphic". This allows the V8 Javascript engine (used in node) to JIT more optimal code.
Behavior Changes:
- Changed union creation logic to retain (rather than elide) redundant literals in some cases. In particular, for type expressions that explicitly include literals along with their non-literal counterpart like
Literal[1] | int
. Retaining these redundant subtypes can be useful for language server features like completion suggestions. - Changed the type of the
__doc__
attribute for a module to always bestr | None
. Previously, pyright changed its declared type tostr
if a docstring was present in the module, but this is incorrect because it's a writable value and can be set toNone
. - Changed logic for explicit specialization to allow
Never
as a type argument for a value-constrained type parameter ifNever
is an explicit constraint.
Published 1.1.371
Bug Fixes:
- Fixed regression that results in a false positive when a traditional type alias (not using PEP 695 syntax) defines a union and is then used as a second argument to an
isinstance
orissubclass
call. - Fixed bug that results in a false positive error when an unpack operator is used in an unparenthesized tuple expression on the RHS of an augmented assignment operator on Python 3.9 and newer.
- Fixed bug that results in a false positive error when using a TypeVar with an upper bound of
type
as a base class in aclass
statement. - Fixed bug that results in false negative when a
list
orset
expression includes more than 64 elements and is being evaluated with a bidirectional inference context. - Fixed type evaluation of old-style (pre-PEP 695) type alias that aliases a generic class when it is used as a direct constructor call.
- Fixed bug that causes a false positive error when an
__init_subclass__
has overloads. - Bumped minimum engine version from 1.86 to 1.89 to match the recently-updated language client library requirements.
Behavior Changes:
- Changed the hard-coded type of the
__class__
symbol to beSelf@T
rather thanT
(whereT
is the enclosing class).
Enhancements:
- Added experimental support for multithreaded type checking in CLI. You can now specify
--threads
followed by an optional thread count. If no count is specified, pyright will use a value equal to the number of logical processors. Experimentation shows that this can speed up type checking by 2x to 3x for larger code bases. It has little or no effect (and possibly negative effects) for small code bases. - Improved detection of the use of variables used in type annotations.
- Improved type narrowing in the fall-through case for sequence patterns when the pattern includes a star pattern and the subject type is a tuple with an indeterminate entry.
- Improved handling of tuple expressions used in type expressions that involve specialization, such as
dict[()]
. - Updated typeshed stubs to the latest version.
- (From pylance) Improved security of python interpreter execution when determining the default python import resolution paths and python version.
Published 1.1.370
Bug Fixes:
- Fixed bug that resulted in a false negative when assigning to type
tuple[Never]
. - Fixed bug that results in incorrect type
isinstance
orissubclass
type narrowing when using a type variable with an upper bound that includes a promotion type. - Fixed recent regression that results in an assertion failure (and therefore a crash) when
type()
is called with dynamic base classes. - Fixed bug that results in a false positive when a protocol includes a method implementation that conditionally raises
NotImplementedError
. - Fixed bug that results in false positive
reportInconsistentOverload
andreportNoOverloadImplementation
errors when an overloaded decorator is applied to a non-overloaded function or method. - Fixed recent regression that results in false positive when a inner function with an inferred return type is a coroutine (async) and is referenced within the function body in which it's declared.
- (from Pylance) Fixed recent regression that results in diagnosticSeverityOverrides to be ignored if a pyproject.toml file is present, even if there is no
[tools.pyright]
section in it. - Fixed bug that results in incorrect type evaluation of a function that accepts a Callable[P, T] and is passed a class object whose constructor needs to be converted to a callable.
- Fixed bug that results in a spurious error when evaluating a quoted (forward reference) type expression that includes an index expression within a
TypeAlias
definition. - Fixed a bug in the type narrowing for the "x is " type guard pattern when
<class>
is a specific class T, as opposed to a variable of typetype[T]
. - Fixed bug that resulted in a false positive error when an abstract class is used for a
NewType
and the new type is constructed. - Fixed bug that results in the incorrect default value of a variadic type variable when the type argument is not provided. It should default to
*tuple[Any, ...]
, not*tuple[Any]
. - Fixed bug that results in a false negative when passing an extra keyword argument to a callable that is parameterized with a ParamSpec.
- Fixed bug that results in a false positive reportUntypedFunctionDecorator error under certain circumstances.
Enhancements:
- Updated typeshed stubs to the latest version.
- Improved analysis performance for complex code flow graphs by adding a cache for reachability.
- Implemented optimization in the protocol matching cache.
- Improved handling of special forms, including TypeAliasType instances, when used in value expressions.