Releases: microsoft/pyright
Releases Β· microsoft/pyright
Published 1.1.396
This is a hot fix release that addresses a regression introduced in 1.1.395 that affected several popular libraries including pandas
.
Bug Fixes:
- Reverted previous bug fix that caused errors to be detected and reported in cases where a library defines a function or method with one or more typed parameters with default arguments whose types are incompatible with the parameter type. Previously, pyright reported these errors in some cases but not in others. The bug fix caused these errors to be consistently reported. However, an unexpected number of libraries are impacted by this change. This reversion will give us time to better understand the extend of the issue and determine the correct long-term solution.
Enhancements:
- Added bidirectional type inference for container types that are parameterized by a protocol that matches a module.
Published 1.1.395
Bug Fixes:
- Fixed a bug that results in noncompliance with the typing spec when a
__new__
method has an explicitAny
return type annotation. In this case, type checkers should assume that the return type of__new__
is not a subtype of the containing class and should therefore ignore the__init__
method. - Fixed bug that results in a spurious "overlapping overload" error if the second both overloads have an
*args
but the first has one or more additional positional parameters - Fixed bug that leads to inconsistent behavior in certain cases involving the evaluation of a call whose target signature involves a parameter with a default argument value, notably where the type of the default value isn't assignable to the declared type of its parameter.
- Fixed a bug that results in a spurious
reportUnknownArgumentType
error under certain circumstances. - Fixed a bug that resulted in a spurious error under certain specific conditions involving a call to a function or method that doesn't have a return type and whose inferred return type is based on variables calculated in a loop.
- Fixed a bug that results in an incorrect error when determining assignability of a function with an
*args
that is unpacked using a*tuple[]
. - Fixed bug that results in a spurious error when an
isinstance
orissubclass
type guard results in a narrowed type that is synthesized as a subclass oftype
and some other class. - Fixed a bug that results in a spurious error when an unpacked iterable argument expression supplies the objects for an
*args
parameter that is annotated with an unpacked TypeVarTuple.
Behavior Changes:
- Exempted
__init__
from override checks even in the case when the override is an object (such as a context manager) rather than a function. - Added special-case logic to permit
type[T]
to be treated as assignable toTypeForm[T]
in accordance with the latest draft of PEP 747. - Changed the interpretation of an async function with an empty body (no yield statement) in a stub file or protocol definition that has a return type annotation of
AsyncGenerator
. Previously, this was assumed to be a generator even though ayield
statement wasn't present. It is now assumed to be aCoroutine
. This behavior is not spelled out in the typing spec, but pyright's new behavior is now consistent with mypy's.
Enhancements:
- Improved error reporting for PEP 728 features when
enableExperimentalFeatures
is not true. - Added error check for member access expressions that attempt to bind an instance or class method to an object or class when the method accepts no "self" or "cls" parameter.
- Added check for invalid creation of
TypeAliasType
outside of a class or module scope. - Updated typeshed stubs to the latest version.
- Added special-case logic to allow
Any
to be defined intyping.pyi
using aclass
statement rather than how it has traditionally been defined.
Published 1.1.394
Enhancements:
- Added missing check for a PEP 695 type parameter being the target of a
nonlocal
statement. This results in a runtime exception, so it should be reported as an error. - Improved error message for TypedDict base classes that are not closed but specify an
extra_items
. Also added check for cases whereclosed
andextra_items
are both specified. - Updated typeshed stubs to the latest version.
- Added missing check for the override of a property that is marked
@final
. - Added support for tracking multiple constraint sets when performing protocol matching. This allows protocols with overloaded methods to contribute independent constraint sets.
Bug Fixes:
- Fixed a bug that results in incorrect handling (and spurious errors) when accessing an attribute on a TypedDict that is shadowed by a TypedDict item.
- Fixed a spec conformance issue relating to callable assignability when the dest type uses an unpacked TypedDict and the source does not accept
**kwargs
. The typing spec indicates that this should fail because TypedDicts are not closed. - Fixed bug that results in incorrect inferred type for an instance or class variable assigned a value as part of a tuple expression target with an unpack operator (e.g.
a, *self.b = (1, 2, 3)
). - Fixed bug that resulted in incorrect type inference for unannotated variables (either local or class-scoped) that are the target of an augmented assignment.
- Fixed a bug that leads to a false negative when checking for partially overlapping overloads that have keyword parameters with default argument values.
- Fixed a bug that causes a false positive "no overload implementation" error when a non-overloaded function uses a decorator that changes its type to a an overloaded function.
- Fixed bug that results in false negative when a format string with a single quote has a newline character within it. This results in a syntax error at runtime.
- Fixed regression that resulted in a false positive error when evaluating a call expression that targets an overloaded method and one of the arguments is an enum with more than 64 members.
- Fixed a bug that results in a false positive "overlapping overload" error under certain circumstances involving recursive types.
- Fixed a bug that results in a false positive error when assigning a tuple of indeterminate length to a zero-length tuple target.
- Fixed a bug that leads to incorrect (unsound) type narrowing when using the
x in y
type guard pattern. Thein
operator uses equality checks, and__eq__
can succeed for objects of disjoint types, which means disjointedness cannot be used as the basis for narrowing here. This change also affects thereportUnnecessaryContains
check, which leverages the same logic. - Fixed recent regression that affected the evaluation of calls that target certain overloads that include an
*args
parameter in the fallback (the last overload). In particular, this affected thezip
constructor. - Removed errant check for
@final
consistency when it is applied toTypedDict
. - Fixed a bug that results in incomplete renames when renaming a class or function that uses PEP 695 type parameter syntax.
Behavior Changes:
- Changed behavior of TypedDict to synthesize a fall-back overload for the
pop
method to handle the case where the caller passes a key name that is not specified in the TypedDict definition. - Changed the type of an
async def
function fromtyping.Coroutine
totypes.CoroutineType
for improved type accuracy. - Exempted
__slots__
symbol when determining whether a class is a callback protocol.
Published 1.1.393
Bug Fixes:
- Changed the fallback type from Unbound to Unknown for the case where pyright determines that a symbol requires code flow analysis but the execution scope exceeds the cyclomatic complexity threshold.
- Fixed a bug that results in a false positive "recursive type definition" error under certain circumstances when the number of declarations for a symbol exceeds the internal threshold of 16.
- Fixed a bug that results in incorrect handling of a "bare" ClassVar annotation either with or without an assignment.
- [From pylance] The default python version was not being picked up from the environment.
- Fixed bug that results in false negative when a parameter is used within a type expression and the parameter's type is a TypeVar or Self.
- Fixed bug that results in a false negative when two import statements shadow the same symbol and an attribute is accessed between the two import statements.
- Fixed bug that results in a crash (due to infinite recursion) if an enum class uses a reference to an enum member in an annotation for that same enum member.
- Fixed a bug that results in incorrect type evaluation when passing a function with a callable parameter that uses Concatenate plus ParamSpec to a function that accepts a callable with just a ParamSpec.
- Added missing check for illegal use of
Final
within a TypedDict or NamedTuple definition. - Tweaked the algorithm for computing the complexity of a code flow graph to accommodate slightly larger graphs before giving up.
Enhancements:
- Updated typeshed stubs to the latest version.
- Added
@override
enforcement for an overloaded method that has no implementation. - Added code to conform with the new checks mandated in the typing spec for
@final
and@override
applied to an overload. - Extended type narrowing for the
X is L
andX is not L
type guard pattern. Previously, narrowing was performed only whenL
was an enum or bool literal. Narrowing is also now applied for other literal types but only in the positive (if
) direction. - Modified the overload call evaluation logic to conform with the new proposed type specification rules regarding
*args
parameters. - Added support for argument type expansion of bool, enums, and tuples of fixed length when evaluating overloads. This behavior is mandated by the new draft typing spec update.
Published 1.1.392
Bug Fixes:
- Fixed bug that results in incorrect evaluation when passing a callable with a "*args" parameter to a callable with a
Concatenate
andParamSpec
. - Fixed bug that results in the
extraPaths
configuration option within an execution extending rather than overriding theextraPaths
provided in the top-level config. - Fixed bug in dictionary expression type inference that results in the incorrect type when a dictionary expansion is used and the resulting expansion type is unknown.
- Improved handling of
__getitem__
,__setitem__
and__delitem__
magic method modeling to handle descriptor objects. - Eliminated type evaluation order dependency that results from return type inference that involves recursion.
- Fixed bug that results in an incorrect "overlapping overload" error message in certain cases involving parameters annotated with
Self
. - Fixed bug that results in a spurious error when an assignment expression (walrus operator) is used as an argument to a constructor call when the constructor has both a
__new__
and__init__
with differing bidirectional type inference contexts. - Fixed bug that results in a spurious "incompatible method override" error when two subclasses with an overloaded method are combined using multiple inheritance.
- Fixed bug that results in an "incompatible method override" false negative when overriding a method that uses class-scoped type parameters with a method that uses method-scoped type parameters.
Behavior Changes:
- Changed error messages to refer to lowercase
list
,dict
andtype
rather than their deprecated uppercase counterparts now that Python 3.8 is EOL'ed. - Improved type narrowing for
issubclass
in the negative ("else") case when the subject type istype
orAny
.
Enhancements:
- Added missing syntax error check for positional argument that follows an unpacked keyword argument in a call expression. Also added a check for an unpack operator used within the first argument of a
cast
call. - Changed code that computes unescaped literal string type to convert CRLF to LF within multi-line triple-quoted strings so the behavior is consistent with runtime.
- Improved error reporting for "async with" statement. Added check that return result of
__aexit__
is awaitable and improved error messages for the case where__enter__
, etc. are present but have incorrect signatures. - Added support for bidirectional type inference for assignment statements that are assigning to an index expression that is subscripted by a slice.
Published 1.1.391
Bug Fixes:
- Fixed a bug that results in a crash under certain circumstances when
Self
is errantly specialized. - Fixed bug that leads to incorrect evaluations when a
ClassVar
andFinal
qualifier are both used on the same dataclass attribute. - Fixed bug that leads to a hang when returning a tuple from a lambda argument expression in certain circumstances.
- Fixed bug that results in incorrect evaluation of a generic dataclass entry when the entry is defined by a generic subclass.
- Fixed bug that leads to a false positive error when
--verifytypes
is used and a subclass overrides an attribute that is generic in the base class. - Fixed bug that results in the command-line version of pyright not handling long file lists provided via stdin.
- Fixed bug that results in spurious type evaluation error when an operator overload method like
__add__
is implemented with a descriptor object. - Fixed bug that results in confusing error messages when using
--verifytypes
while targeting a submodule within a package and that submodule is a single-file module. - Fixed recent regression in
isinstance
type narrowing logic that affects the case where the filter type is a metaclass. - Fixed bug that results in order-dependent type errors under certain circumstances involving converter functions in a dataclass.
Enhancements:
- Improved error message for incorrect exception type in an
except
clause. - Added exemption to the
reportUnnecessaryComparison
rule for simple wildcard patterns in acase
clause.
Published 1.1.390
Bug Fixes:
- Fixed recent regression that results in incorrect narrowed type when using the
x in y
pattern wherey
is a container type whose element type isUnknown
orAny
. - Fixed bug that causes a false positive overlapping overload error when the overload accepts a
Callable[..., T]
form. - Fixed a bug that results in a hang under certain circumstances when using a recursive type alias.
- Fixed a bug that leads to a false positive when a function is decorated and has no explicit return type annotation and the body references the decorated function in a loop.
- Fixed a bug that leads to incorrect type evaluation when
__getitem__
is set to a callable object. - Fixed bug that results in confusing error message when there is a partially-unknown metaclass type detected by the
--verifytypes
command.
Enhancements:
- Updated typeshed stubs to the latest version.
- Added check for
\u
and\N
escapes within bytes literals, which are illegal. - Added support for a "bare"
Final
annotation in a dataclass entry that has a default value assigned to it. - Improved dataclass converters to support generic types.
- Added check for importing a
Final
variable from another module and then attempting to overwrite it. - Added check for an attempt to assign to a module-local variable if it is shadowing a
Final
variable declared by the builtins module or some other chained file. - Added support for evaluating the
slice
class type arguments for slice expressions. - Added check for invalid use of
ClassVar
qualifier within aNamedTuple
orTypedDict
attribute annotation.
Behavior Changes:
- Changed inference logic for exception groups to more closely match the runtime. If a non-base exception is targeted, the inferred type is now
ExceptionGroup
rather thanBaseExceptionGroup
.
Published 1.1.389
Bug Fixes:
- Fixed bug that results in a false negative if a
|
union operator creates a union of generic types. These types should be specialized with default type arguments. - Fixed bug that results in false negative when raising a value of type
None
. - Fixed bug that results in an incorrect type evaluation when a
match
statement uses a pattern with a target expression that overwrites the subject expression. - Fixed bug that results in a missing
reportUnknownArgumentType
error if the argument is an expression involving an__init__
parameter in an unannotated (pseudo-generic) class. - Fixed bugs that resulted in false positive errors when using an expression of the form
type(A)
as a base class or a metaclass in a class definition. - Fixed bug that leads to false positive when a method is overridden by a polymorphic method.
- Fixed bug that affects pyproject.toml files with an emoji character by switching to a different toml parser.
- Fixed a bug that results in a false negative when a class is used in a type annotation for a method parameter and both the class and the method are generic and use PEP 695 syntax.
- Fixed a bug that results in a false positive "--verifytypes" error when using an explicit
TypeAliasType
call to create a public symbol in a "py.typed" library. - Fixed bug that results in the incorrect detection of an asymmetric descriptor if the descriptor class is generic.
Enhancements:
- [From Pylance]: Improved signature help to skip keyword-only params with invalid names.
- Added checks for
except*
clause to report invalid usage that is flagged as a syntax error at runtime. - Added check for the illegal use of an
await
keyword in a lambda. - Added missing checks for illegal use of
await
andasync
within list, set and dictionary comprehensions within a non-async function. - Improved a confusing error message that results when a class is assigned to an incompatible class.
- Added narrowing support for a TypedDict value, which can be assumed never to be falsy if it has at least one required entry.
- Improved the "x is y" and "type(x) is y" type guards to better handle the case where
x
is a TypeVar. - Updated typeshed stubs to the latest version.
Published 1.1.388
Bug Fixes:
- Fixed a bug that results in a false positive when a class is defined within a generic function and uses type parameters from that function.
- Fixed a bug that results in unexpected constraint solver results in certain cases involving arguments with lambda expressions.
- Fixed bug that results in false positive under certain circumstances involving classes parameterized with a contravariant type variable.
- Fixed bug that results in incorrect evaluation of class variables assigned in an
__init_subclass__
or__class_getitem__
method. These methods are implicitly class methods even though they are not decorated with@classmethod
. - Removed recent check for illegal identifiers used in
alias
fordataclass_transform
field. This isn't an illegal condition, so the resulting error was a false positive. Instead, changed completion provider to not suggest the illegal identifier as a valid keyword argument.
Enhancements:
- Enhanced the special-case logic for functools.partial so it handles the case where the function has a
**kwargs
parameter typed with an unpacked TypedDict. - Improved the synthesized type of the
keys
,values
anditems
methods on a closed TypedDict to provide a more precise (narrower) type for the key values. - Improved the handling of a TypeVar whose definition involves a circular definition.
- Added check for
__slots__
initialization when the__slots__
list is empty and the class is marked@final
.
Published 1.1.387
Bug Fixes:
- Fixed bug that leads to a false negative when passing multiple
*args
or**kwargs
arguments to a callable parameterized by a ParamSpec. - Fixed issue that results in a false positive "type could not be determined because it refers to itself" error caused by a false dependency due to narrowing logic. This may also improve type analysis performance in some code.
- Switched to a different toml parser to avoid incompatibility with the latest toml standard.
- Changed the evaluated type of an
in
ornot in
operator to bebool
if the LHS doesn't support containment. Previously, the expression evaluated toNever
. - Fixed a bug that results in a false positive when a class parameterized by a TypeVarTuple is used in conjunction with a Self type.
- Fixed bug that results in incorrect type evaluation when performing protocol matching that involves an attribute with a callable type parameterized by a ParamSpec.
- Added protection for an internal call stack overflow when inferring return types in deep call hierarchies within untyped code.
- Fixed a false positive "incompatible method override" error in a case that involves both class-scoped and method-scoped type variables.
- Fix recent regression that broke hover text on
.get()
ofTypedDict
instance. - Fixed a bug that causes a false positive error when a class uses
type(Protocol)
as a base class.
Enhancements:
- Enhanced type narrowing logic for "x == " type guard pattern to handle the case where
x
is a type variable with a literal upper bound or value constraints that are literals. - Improved detection of asymmetric descriptors to handle the case where the
__set__
and__get__
methods are overloaded. - Added experimental support for draft PEP 764: Inlined typed dictionaries.
- Changed check in the pyright VS Code extension for the presence of Pylance. If Pylance is installed in the workspace but is not configured to be loaded (i.e. the "python.languageServer" is set to "None"), then pyright will allow itself to be loaded.