Releases: microsoft/pyright
Published 1.1.354
Bug Fixes:
- Fixed a bug that resulted in an incorrect type evaluation when an augmented assignment is used within an inner-scoped function to add a constant to a variable. Literal math should not be used in this case.
- Fixed two bugs that resulted in false negatives when redefining a constant variable with a non-variable symbol and when redefining a Final variable with a non-variable symbol.
- Fixed bug that results in false positive when a generic class or type alias uses a TypeVarTuple followed by one or more ParamSpecs that have default values.
- Fixed bug that resulted in false negative when narrowing a constrained or bound TypeVar with a
complex()
orfloat()
class pattern. - Fixed bug that results in a false positive under certain circumstances when a constrained TypeVar is used as the default for another constrained TypeVar.
- Fixed a bug that results in a false positive under certain circumstances when defining a type alias using the old
typing.TypeAlias
annotation. - Fixed a bug that results in a false negative when a class explicitly inherits from a protocol that defines an instance variable but the child re-declares as a
ClassVar
without an explicit type. - Fixed a bug that made locale overrides through environment variables no longer work on node 21.
Enhancements:
- Enhanced handling of
type
function when it is passed a class. Pyright previously evaluated this asAny
, but now it returns the class' metaclass. - Added check for generic classes and type aliases that include a TypeVarTuple followed by a TypeVar that has a default value. This is illegal according to PEP 696.
- Changed the behavior when accessing a class attribute from a generic class that is not specialized. The class is now automatically specialized in the case using default type parameter values (from PEP 696) or Unknown. This change is required for conformance with PEP 696.
- (From pylance) Added some optimizations to the tokenizer to reduce memory usage.
- Added new
reportUnhashable
diagnostic rule.
Published 1.1.353
Breaking Changes:
- The CLI and language server versions of pyright now require a minimum node version of 14. Previously node 12 and 13 were supported.
Enhancements:
- Enabled PEP 705 and PEP 696 functionality without the use of enableExperimentalFeatures now that these PEPs are officially accepted.
- Improved support for instance variables whose type is declared in a metaclass. Pyright now honors this type and enforces type consistency in derived classes.
Bug Fixes:
- Fixed a bug that results in a false negative when a dundered method overrides a base class method of the same name and uses different parameter names along with different types.
- Fixed a bug that leads to a false positive error when a
match
statement is used in a loop and the subject expression is potentially narrowed as a result of thematch
statement. - Added check for inappropriate use of
Annotated
passed as second argument toNewType
call. - Fixed a bug that results in a false positive error when expanding the type arguments to a TypeVarTuple under certain circumstances.
- Fixed a bug that results in incorrect type evaluation when an index expression is assigned a value within a doubly-nested loop under certain circumstances.
- Fixed a regression that caused the signature help provider to not display the
__new__
method of a constructor if it is overloaded. - Fixed hard-coded type information for module attribute
__package__
. It should bestr | None
rather thanstr
. - Fixed a bug in the
isinstance
type guard logic. It was not properly handling tuples that included unions. - Fixed bug in signature help provider so
str
method docstrings are showed when called onLiteralString
. - Fixed a bug that results in incorrect type narrowing behavior for member access expressions under certain circumstances.
- Fixed bug that resulted in a false negative when a possibly-unbound variable is captured by an inner scope under certain circumstances.
Published 1.1.352
Enhancements:
- Implemented provisional support for PEP 728 (support for extra items within TypedDicts). You must set enableExperimentalFeatures to true for now.
- Added support for concatenated strings used in a
@deprecated
decorator. - Added support for call-site return type inference for class and instance methods.
- Improved handling of
enum.nonmember
in cases where the attribute has a declared type. - Added missing check for inappropriate use of
InitVar
outside of a dataclass.
Behavior Changes:
- Added special-case handling for 'typing_extensions' module whose stubs are part of typeshed's stdlib stubs even though it is not part of stdlib.
- Refined the heuristic for when to use bidirectional type inference for the RHS of
and
andor
operators. - Changed behavior of command-line "--pythonversion" and "--pythonplatform" options so they now override the same-named options in the config file.
Bug Fixes:
- Fixed a bug that resulted in a false negative when attempting to use
TypedDict
orProtocol
as an upper bound when using PEP 695 syntax. - Fixed a bug that resulted in "reportUnnecessaryTypeIgnoreComment" diagnostics to be generated even if the source file was in the "ignore" list.
- Fixed a bug that leads to incorrect type inference for a lambda when passed to a constructor in certain circumstances.
- Fixed a bug that leads to a false positive type violation when reassigning a value within a loop and the target variable has a declared type of a constrained type variable.
- Fixed a bug that results in a false negative when passing an unpacked dict of the wrong type to a function that contains a positional-only parameter marker plus one or more keyword parameters.
- Fixed a bug in the import resolver that resulted in an incorrect resolution when an import within a
__init__.py
file uses the formfrom .a import a
. - Fixed a bug that results in a false positive error when an
await
expression is passed as an argument to an overloaded function. - Fixed a bug that results in an incorrect "Unbound" type evaluation for a variable assigned within a loop.
Published 1.1.351
Bug Fixes:
- Fixed bug that results in a false positive "no overload implementation" error if an overloaded function is passed through a decorator that uses a ParamSpec.
- Fixed a recent regression that results in a false positive error when an
Enum
subclass overrides__new__
or__init__
and then a subclass of that class assigns tuple values when defining enum members - Fixed a bug that results in a false positive error when a method defined within a named tuple is overridden by a subclass
- Fixed a bug that results in a false positive error when a
enum.nonmember
value is assigned to a class-scoped variable with a type annotation in an Enum class. - Fixed a bug in the type narrowing logic for class pattern matching that resulted in incorrect narrowing in the negative (fall-through) case.
- Added missing check for inappropriate use of an unpacked TypeVarTuple within a TypeAliasType type parameter list.
- Fixed a false positive
reportUnknownArgumentType
error when assigning an empty list or dict expression to an index expression subscripted with a slice. - Fixed bug that results in a false positive error when assigning a tuple value that includes an unpacked TypeVarTuple to another tuple that also includes an unpacked TypeVarTuple.
- Fixed bug that results in a false positive error when calling
update
on a TypedDict with zero defined entries. - Fixed a bug that results in a false positive with the
reportUnnecessaryCast
check if the second argument is a special form. - Fixed a bug that led to incorrect type evaluation for a call that targets a generic function that uses a default argument for one of the generic parameters.
Behavior Changes:
- Change the heuristic for determining whether a metaclass supports
__or__
. In the case where the metaclass derives from Any or Unknown, pyright now assumes that it doesn't override__or__
. - Changed behavior of CLI's
--watch
mode. Previously, it reported diagnostic deltas when it detected a change, but it is more useful if it reports all remaining diagnostics even for files that it didn't reanalyze due to a file change.
Enhancements:
- Updated typeshed stubs to the latest version.
- Added provisional support for draft PEP 742 (TypeIs).
- Added check for the use of an implicit position-only parameter (one that starts with a double underscore) that is located after a non-position-only parameter.
Published 1.1.350
Bug Fixes:
- Fixed a bug that resulted in an incorrect type evaluation when a TypeVar with a default (PEP 696) was used in an overload but was not solved.
- Fixed a bug that results in a false negative when a
None
type is included in an unpacked argument within a function call. - Fixed a bug that results in a false positive error when a TypeVar bound to a union of literals is used in the specialization of a TypeAlias whose TypeVar is bound to a wider union of literals.
- Fixed bug in
isinstance
type narrowing logic that leads to incorrect narrowed type when the filter type (the second argument) and the test type (the first argument) are both type variables.
Behavior Changes:
- Changed behavior of
super()
method call whenself
is annotated as a protocol class. This pattern is used for annotating mix-ins. In this case, pyright should not generate an error if the protocol's method isn't implemented. - Added code to deduplicate references returned by the textDocument/references LSP call.
Enhancements:
- [contributed by @Seairth] Added multi-root workspaceFolder support in path variable expansion.
- Improved logic for unpacked arguments that contain an "Unbound" type.
- Improved handling of unreachability analysis for an "implied else" (an if/elif chain that is missing a final "else" clause).
- Added check for an attempt to override a field in a named tuple within a subclass.
- Added check for an attempt to delete a named tuple entry.
- Added check for use of
TypedDict
orNamedTuple
as second argument toisinstance
call, which isn't allowed. - Added check for out-of-bound index accesses for named tuple instances.
- Improved misleading diagnostic message when attempting to call a special type form.
- Updated typeshed stubs to the latest version.
Published 1.1.349
Bug Fixes:
- Fixed default for
reportImplicitStringConcatenation
in schema file. - Fixed a bug that resulted in an incorrect type evaluation for a union type used as a runtime expression. The type should be
UnionType
, nottype[UnionType]
. - Fixed regression that resulted in a false positive error when calling an abstract method on an abstract class that passes through the constraint solver (e.g. a generic decorator).
- Fixed a bug that results in a false positive when using a TypeVarTuple to capture the parameters of a generic callable that includes one or more default argument values.
- Fixed bug in tuple type compatibility logic that resulted in a false negative when dest type includes an upacked unbounded tuple plus additional entries.
- Fixed bug in tuple type compatibility logic that resulted in a false positive when dest type is
tuple[Any, ...]
. - Fixed a bug that results in a false negative when the literal
typing.Any
is passed to a function that accepts atype[T]
.Any
is a special form and should not be compatible withtype
. - Fixed bug that resulted in incorrect type evaluation when a TypeAliasType is used in a value expression.
- Fixed a bug that resulted in incorrect type evaluation when calling a
tuple
constructor with bidirectional type inference and the value passed to the constructor is anIterable[Any]
. - Fixed a bug that resulted in incorrect type narrowing for sequence patterns when the subject expression contains a tuple with an unbounded component.
Behavior Changes:
- Removed name consistency match for functional form of Enum. After a discussion in the typing community, it was decided that name consistency checks in some cases were unnecessary and inappropriate for type checkers.
- Changed the way pyright translates
tuple[()]
into a specializedSequence
. It used to translate it toSequence[Any]
, but the typing spec now clarifies that it should beSequence[Never]
. - Changed handling of
tuple
with multiple unpacked embedded tuples. Type spec now clarifies this is OK as long as there are not multiple unbounded embedded tuples. - Added special-case logic to handle
__name__
and a few other instance variables defined in thetype
class so they are treated specially when accessed from a class instance.
Enhancements:
- Added check for inappropriate use of
Final
in a value expression. - Added support for enum member aliases defined within an enum class.
- Improved error messages for tuple type mismatches that involve tuples with indeterminate types.
- Added check for the use of
Annotated
or a type alias defined withAnnotated
as the second argument to anisinstance
orissubclass
call. This produces an exception at runtime. - Added additional performance enhancements specifically for large unions of literal types.
Published 1.1.348
Breaking Changes:
Many pyright users have requested finer-grained control over diagnostics βΒ especially for diagnostics that were previously lumped under the catch-all rule reportGeneralTypeIssues
. I was hesitant to do this because it is a breaking change and could be disruptive for some pyright users. However, the time has come to make this change.
The list of new diagnostic rules includes:
- reportAbstractUsage
- reportArgumentType
- reportAssertTypeFailure
- reportAssignmentType
- reportAttributeAccessIssue
- reportCallIssue
- reportInconsistentOverload
- reportIndexIssue
- reportInvalidTypeArguments
- reportInvalidTypeForm
- reportNoOverloadImplementation
- reportOperatorIssue
- reportPossiblyUnboundVariable
- reportRedeclaration
- reportReturnType
- reportUnusedExcept
Refer to the configuration documentation for more details about each of these.
This is a breaking change for code bases that were previously overriding the diagnostic severity for reportGeneralTypeIssues
in the config file, in file-level pyright comments or in # type: ignore
or # pyright: ignore
comments. You will need to update your configuration settings and comments to use the new diagnostic rule names.
Bug Fixes:
- Fixed bug in pyright's "type printer" that resulted in an incorrect output when printing a specialized type alias parameterized by a TypeVarTuple that has a value that contains a tuple with an indeterminate length.
- Fixed a bug that resulted in an incorrect type evaluation when a generator uses an
await
operator within the left-mostfor
. This shouldn't result in anAsyncGenerator
despite what the Python documentation indicates. - Fixed a bug in the
isinstance
type narrowing logic whentype
is filtered using a metaclass instance. - Fixed recent regression that resulted in a crash when using certain language server features with an absolute
extraPaths
value. - Fixed spec conformance issue with TypeVarTuple constraint solving. The spec indicates that if a TypeVarTuple is used multiple times in a callee's signature, the tuple must "match exactly".
- Addressed a bug that led to a false positive (missing error) when a "bare" TypeVar is used as a base class in a class statement.
- Fixed a bug that masked an error (false negative) under certain circumstances when evaluating a lambda.
- Fixed a bug that resulted in a false positive error and incorrect type evaluation when an assignment expression (walrus operator) is used in a comprehension.
- Changed diagnostic rule for the case where
Callable
is missing a second type argument. It should usereportMissingTypeArgument
. - Fixed a bug that led to a false negative when an illegal form of tuple was used:
tuple[*tuple[str], ...]
.
Behavior Changes:
- Changed handling of
tuple[Any, ...]
so it is treated as though it's bidirectionally type compatible with all tuples regardless of length. This change is made in response to a clarification in the typing spec. It brings pyright in alignment with mypy's behavior in this regard.
Enhancements:
- Added check for name mismatch for enum classes defined using the functional syntax.
- Improved handling of custom Enum classes (those that derive from
Enum
or useEnumMeta
). - Added special-case logic for enum classes that are invoked as though they are being constructed.
- Added type enforcement for the
_value_
type in an Enum class. Also added enforcement for custom__new__
and__init__
method signatures. - Improved handling of
Annotated
and other special forms when they are used in runtime value expressions rather than annotations. - Added error reporting for the situation where a generic instance variable is accessed through a class object.
- Updated typeshed stubs to the latest version.
Published 1.1.347
This is a quick-turn release to fix a regression that affected 1.1.346.
Bug Fixes:
- Fixed regression that caused JSON output of CLI to not follow the documented schema.
Enhancements:
- Added support for Python 3.11 enum features:
enum.member
andenum.nonmember
. - Added new language server setting
pyright.disableTaggedHints
to disable the use of diagnostics hints with tags. Some language server clients do not display these tagged hints in the intended manner and instead treat them as regular diagnostics. - Changed all diagnostics (other than syntax errors and a few special informations) to have an associated diagnostic rule. Previously, some diagnostics had no associated rule.
- Added support for @no_type_check decorator.
Published 1.1.346
Bug Fixes:
- Added code to properly print a f-string expression in pyright's "expression printer". This affected stub generation if an f-string was used (e.g. in call to a decorator).
- Fixed a bug that resulted in a false positive error when using a bound TypeVar in an
except
statement. - Fixed a bug that led to a false negative when using a non-data protocol class in a tuple within an
issubclass
check. - Fixed a bug that resulted in incorrect inference of an async generator expression if an
await
keyword was used in afor
iterator expression. - Fixed a bug that resulted in an incorrect type evaluation for a sliced tuple if the end of the slice is the same as the tuple length (off-by-one error).
- Fixed recent regression that results in a false positive error when an unpack operator is used in an
Annotated
type annotation. - Fixed false negative when a special form is assigned to a value declared as type[T] or when instantiated.
- Added support for generic type alias specialization when the type alias includes an unpacked TypeVarTuple and the specialization list includes an unpacked unbounded tuple.
- Fixed bug that led to incorrect protocol matching for class objects.
- Fixed recent regression whereby a type created with
NewType
was no longer allowed as an argument for anotherNewType
. - Fixed a bug that resulted in an incorrect implied specialization of a generic type alias that is parameterized by a TypeVarTuple. The implied type argument should be
*tuple[Unknown, ...]
in this case. - Fixed a bug in class pattern matching logic that incorrectly narrows types when using a
str()
class pattern and aLiteralString
subject. - Fixed bug that caused "final method override" diagnostic to have no associated diagnostic rule.
- Fixed a bug that resulted in incorrect variance inference for protocols (and for PEP inferred-variance TypeVars in PEP 695) when a
self
orcls
parameter is explicitly annotated with a type that includes the type parameter. - Fixed a bug that resulted in a false positive when a contravariant TypeVar was used in a return type in a non-method.
Behavior Changes:
- Changed the way pyright identifies an "unimplemented protocol method" within a stub file. It now looks at whether the method is decorated with
@abstractmethod
. Previously, it assumed all such methods were potentially implemented. - Changed error reporting for non-protocol classes that derive from a protocol but don't implement all of the unimplemented symbols in the protocol. Previously, pyright reported the error on the class declaration. Now, it reports it at instantiation time. This is more consistent with what other type checkers do.
Enhancements:
- Updated typeshed to the latest version.
- Added provisional support for proposed extension to typeshed's VERSION mechanism (python/typeshed#11260).
- Added support for
+
unary operator inLiteral
int
type annotations. The typing spec was recently amended to allow this. - Improved handling of special forms defined in the typing module so they are treated correctly when used as runtime objects.
Published 1.1.345
Bug Fixes:
- Fixed bug that led to false negative when a list expression was used within the first type argument of an
Annotated
type expression. - Added a missing error condition for a non-method function that is marked
@final
. - Fixed crash related to a regression introduced with recent internal URI tracking.
- Fixed false negative for a
TypeVarTuple
constructor call that includes value constraints. - Fixed a bug that led to an incorrect type evaluation for an explicitly-specialized class parameterized with a ParamSpec.
- Fixed bug that resulted in incorrect type evaluation when a PEP-695 TypeVar is shadowed by an identifier of the same name within an inner scope.
- Added missing check for inconsistent use of
@final
in an overloaded function. Added missing check for override of an overloaded method marked@final
. - Fixed bug in protocol matching logic to reject a protocol match if a variable is a
ClassVar
in the protocol but not in the concrete class (or vice versa). - Fixed bug that leads to a false positive when a generic property is defined within a protocol.
- Fixed a bug that led to incorrect type evaluation when a constrained TypeVar includes literal types as constraints.
- Added missing check for the specialization of a generic type alias that includes a TypeVarTuple plus two or more TypeVars.
- Fixed a bug that resulted in a false negative when specializing a generic type alias parameterized by a regular TypeVar with an unpacked tuple.
- Added missing error for an illegal unpacked argument in type argument list.
- Fixed a bug that led to a duplicate error message when defining a class-scoped type alias.
Enhancements:
- Improved error message for protocol classes that derive from non-protocol classes.
- Improved error reporting for incompatible overrides.
- Added code to report when the
Concatentate
special form is used in an illegal context. - Added support for constants for field names in
NamedTuple
call. - Improved evaluation logic for tuple slices. It now works in cases where the tuple includes unbounded entries or unpacked TypeVarTuples.
- Improved type analysis performance in certain cases involving complex code flow graphs and "truthy" conditional statements.
- Added check for a call to an unimplemented method in a protocol from a base class that explicitly calls it.
- Implemented small performance improvement by not generating error messages during protocol TypeVar variance validation.
- Added check for data protocols used in an
issubclass
call. PEP 544 indicates that this isn't allowed. - Added check for "unsafe overlaps" for a runtime-checkable protocol when used in an
issubclass
orisinstance
check.
Behavior Changes:
- Changed CLI to sort diagnostics by location within a file.
- Removed support for
Union[*Ts]
andUnion[*tuple[...]]
. This functionality was included in an early draft of PEP 646 but was dropped in the final spec. The functionality can still be used in pyright ifuseExperimentalFeatures
is set to true, but it will likely be removed entirely in the future.