Releases: microsoft/pyright
Releases Β· microsoft/pyright
Published 1.1.398
Bug Fixes:
- Fixed bug that results in a spurious type error when a ParamSpec is used in conjunction with a dataclass and a contextmanager.
- Fixed recent regression that results in a false negative when calling a function with a positional-only parameter whose type is generic and has a concrete default argument value.
- Fixed regression that results in an
Unknowntype evaluation where previouslyAnywas generated during bidirectional type inference. - Fixed bug that results in incorrect overload resolution when an unpacked argument is of unknown length and potentially matches multiple overloads.
- Fixed bug that results in a variable being displayed as "not accessed" if it's used in an argument expression for a call expression whose base type is a module or
None. - Fixed bug that results in a hang under certain very specific circumstances involving a protocol method that has been decorated in such a way that it can no longer be bound to the owning protocol class.
- Fixed a bug that contributes to inconsistent type evaluation results when using the "--threads" feature.
- Fixed bug that results in incorrect "literal math" result when dividing
Literal[0]by a negative literal int value. - Fixed a bug in "literal math" for shift operators. If the RHS value is negative, the operation is invalid, so literal math shouldn't be applied.
- Fixed bug in "literal math" logic for modulo and floor divide operators that affect cases where operands have different signs.
Behavior Changes:
- Changed algorithm for applying type narrowing upon assignment when one or both of the declared type or assigned type contain "Any".
- Removed special-casing for async functions that skips check for implicit return when the return type is
NoReturn.
Enhancements:
- Updated typeshed stubs to the latest version.
- Extended
reportPrivateImportUsageto report the use of symbols imported from private submodules in a "py.typed" or stub library. - Extended the
reportUnnecessaryComparisioncheck to support the patternsx is Noneandx is not Nonein cases wherexis provably disjoint in type. - Added generalized support for assignment expressions (walrus operators) for type guards.
- Extended the type narrowing logic for the
x == Ltype guard pattern so it supports the case wherexisLiteralStringandLis a string literal.
Published 1.1.397
Bug Fixes:
- [From pylance] Fix problem with partial stub service not being part of Pyright CLI.
- Added additional special-casing to
x in ytype guard logic to handleLiteralStringvalues. - Partially eliminated inconsistent error reporting when calling a function with a default argument that is not assignable to the declared parameter type. An error will still be reported in the case where the declared parameter type includes an unsolved type variable in most cases, but it will no longer be reported if the unsolved type variable is due to a pseudo-generic class.
- Fixed bug that results in an identifier being marked "unaccessed" if it is used in an argument expression to a call whose type is possibly unbound.
- Fixed bug that leads to a false negative when evaluating a call expression where the callable type is
Anyand an argument expression uses dictionary unpacking but the operands type is not a mapping. - Fixed a bug that results in an incorrect "Unknown" type evaluation under certain circumstances involving an assignment to an annotated variable within a loop.
- Fixed bug that results in incorrect bidirectional type inference when using nested constructor calls for dataclasses.
- Fixed a bug that results in incorrect "literal math" results when using a floor divide
//operator with literal operands whose signs differ. - Fixed a bug that results in a hang under certain circumstances when inferring the return type of a recursive function.
Enhancements:
- Changed type evaluator to make a best effort to evaluate the return type of a function call even if arguments are missing.
- [From pylance] Implement support for pull diagnostics in pyright.
- Added code to enforce that an argument in a call expression that is unpacked is iterable.
- Improved support for unused import detection for import statements that target multi-part names.
Behavior Changes:
- Changed the type of
__path__fromIterable[str]toMutableSequence[str]. Both are correct, but the latter is more precise. - Improved determinism of
--threadsdiagnostic output by always sorting output by file path. - Improved reproducibility of CLI diagnostics in non-threaded case by sorting output by file path.
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 explicitAnyreturn 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
*argsbut 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
reportUnknownArgumentTypeerror 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
*argsthat is unpacked using a*tuple[]. - Fixed bug that results in a spurious error when an
isinstanceorissubclasstype guard results in a narrowed type that is synthesized as a subclass oftypeand some other class. - Fixed a bug that results in a spurious error when an unpacked iterable argument expression supplies the objects for an
*argsparameter 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 ayieldstatement 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
enableExperimentalFeaturesis 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
TypeAliasTypeoutside of a class or module scope. - Updated typeshed stubs to the latest version.
- Added special-case logic to allow
Anyto be defined intyping.pyiusing aclassstatement 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
nonlocalstatement. 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 whereclosedandextra_itemsare 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 ytype guard pattern. Theinoperator 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 thereportUnnecessaryContainscheck, which leverages the same logic. - Fixed recent regression that affected the evaluation of calls that target certain overloads that include an
*argsparameter in the fallback (the last overload). In particular, this affected thezipconstructor. - Removed errant check for
@finalconsistency 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
popmethod 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 deffunction fromtyping.Coroutinetotypes.CoroutineTypefor 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
Finalwithin 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
@overrideenforcement for an overloaded method that has no implementation. - Added code to conform with the new checks mandated in the typing spec for
@finaland@overrideapplied to an overload. - Extended type narrowing for the
X is LandX is not Ltype guard pattern. Previously, narrowing was performed only whenLwas 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
*argsparameters. - 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
ConcatenateandParamSpec. - Fixed bug that results in the
extraPathsconfiguration option within an execution extending rather than overriding theextraPathsprovided 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,dictandtyperather than their deprecated uppercase counterparts now that Python 3.8 is EOL'ed. - Improved type narrowing for
issubclassin the negative ("else") case when the subject type istypeorAny.
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
castcall. - 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
Selfis errantly specialized. - Fixed bug that leads to incorrect evaluations when a
ClassVarandFinalqualifier 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
--verifytypesis 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
--verifytypeswhile targeting a submodule within a package and that submodule is a single-file module. - Fixed recent regression in
isinstancetype 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
exceptclause. - Added exemption to the
reportUnnecessaryComparisonrule for simple wildcard patterns in acaseclause.
Published 1.1.390
Bug Fixes:
- Fixed recent regression that results in incorrect narrowed type when using the
x in ypattern whereyis a container type whose element type isUnknownorAny. - 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
--verifytypescommand.
Enhancements:
- Updated typeshed stubs to the latest version.
- Added check for
\uand\Nescapes within bytes literals, which are illegal. - Added support for a "bare"
Finalannotation in a dataclass entry that has a default value assigned to it. - Improved dataclass converters to support generic types.
- Added check for importing a
Finalvariable 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
Finalvariable declared by the builtins module or some other chained file. - Added support for evaluating the
sliceclass type arguments for slice expressions. - Added check for invalid use of
ClassVarqualifier within aNamedTupleorTypedDictattribute 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
ExceptionGrouprather 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
matchstatement uses a pattern with a target expression that overwrites the subject expression. - Fixed bug that results in a missing
reportUnknownArgumentTypeerror 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
TypeAliasTypecall 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
awaitkeyword in a lambda. - Added missing checks for illegal use of
awaitandasyncwithin 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
xis a TypeVar. - Updated typeshed stubs to the latest version.