Releases: microsoft/pyright
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.
Published 1.1.344
Bug Fixes:
- Fixed bug that caused "go to definition" and semantic rename to not work for forward-declared symbols referenced in a "type" type alias definition.
- Fixed bug in parser that resulted in an incorrect syntax error when certain expression forms were used with the
type
statement to define a type alias. - Fixed a bug that resulted in a false negative when attempting to access valid attributes from a type alias created via a call to the
TypeAliasType
constructor. - Fixed a bug that led to an incorrect type evaluation when explicitly specializing a generic class or type alias with a ParamSpec.
- Fixed a bug that led to a false positive "not awaitable" error if the
__await__
method return type was Unknown. - Fixed a bug that results in a false negative when the
TypeAliasType
constructor is called with an expression that refers to a traditional TypeVar. - Fixed a bug that leads to a false negative when validating type compatibility between two callables and the source has a position-only parameter corresponding to a non-position-only parameter in the dest.
- Fixed bug in code flow analysis that resulted in an incorrect type evaluation when a "NoReturn" call is made within a code block protected by an exception-suppressing context manager.
Behavior Changes:
- Added LSP exemption for
__post_init__
method. - Improved overload overlap logic to detect partial overlaps when parameter types include unions that intersect.
Enhancements:
- Improved logic that determines whether the expression used for a
type
statement or a call toTypeAliasType
is a valid type expression. - Added additional checks for invalid
NewType
calls. - Improved detection of invalid type alias expressions for implicit (traditional) type aliases.
- Improved error reporting for
with
statement when__enter__
or__aenter__
is present but cannot be bound.
Published 1.1.343
Bug Fixes:
- Fixed bug that resulted in crash when using language server APIs in certain circumstances.
- Fixed bug that resulted in incorrect type evaluation of a variable within a loop under certain conditions.
- Fixed a bug in the function type assignment logic that leads to a false positive under certain circumstances involving a ParamSpec in an overload with a callback that includes a positional-only parameter separator.
- Fixed a bug that leads to a false negative when
Self
is used within a class definition statement. PEP 637 explicitly rejects this usage ofSelf
. - Fixed a bug that leads to a false negative when
Self
is used within a metaclass. PEP 637 explicitly rejects this usage ofSelf
.
Enhancements:
- Eliminated some unnecessary work when determining the effective type of a symbol that doesn't have a declared type. When evaluated in the context of a particular usage, it's unnecessary to evaluate any assignments within the same execution scope.
- Add error checking for illegal use of unary, binary, or ternary operators within a type annotation.
- Added detection of invalid keyword arguments in
TypedDict
class definition when using the normal class syntax. - Added detection of a call to
TypedDict
alternative syntax form that assigns the resulting class to a variable whose name doesn't match the name specified in theTypedDict
call. - Added check for the use of a TypedDict class in an
isinstance
orissubclass
call. These generate a runtime exception.
Published 1.1.342
Bug Fixes:
- Fixed
@deprecated
functionality that was broken by a recent change to the typeshed stubs (which replaced a function with a class). - Fixed bug that results in a false positive error under certain circumstances when calling an inner function that uses a ParamSpec defined scoped to an outer function.
- Fixed a bug in the
--verifytypes
CLI feature that resulted in a false negative when docstrings are missing from a class or function that is defined in a private module but re-exported from a public module. - Fixed a bug that led to a combinatoric explosion and an infinite loop in certain edge cases involving a class with an untyped constructor and methods that return recursive types.
- Fixed a bug that led to false negative errors when doing protocol matching with a method that uses
Self
in its signature. - Increased internal limit of the number of overload signatures that can be captured by a ParamSpec from 64 to 1024.
- Fixed a bug that leads to infinite recursion (stack overflow) under certain circumstances.
Enhancements:
- Added narrowing support for literal patterns in a
match
statement that are used to discriminate between tagged unions of objects that can be discriminated based on a field with a literal type.
Published 1.1.341
Normally, new pyright releases are published each Tuesday. This is an out-of-cycle release that addresses several regressions introduced in 1.1.340. These were all related to a massive change (one that affected a majority of the source files in pyright) that changed the way that file paths were tracked internally. Pyright now uses URIs rather than simple paths βΒ a change that's needed to support a number of language server features.
Bug Fixes:
- Fixed regression introduced in 1.1.340 that caused a crash in the
--verifytypes
functionality. - Fixed regression introduced in 1.1.340 that resulted in an incorrect URI returned as part of a language server "rename" request.
- Fixed regression introduced in 1.1.340 that resulted in an unintended schema change for the
outputjson
output. - Fixed regression introduced in 1.1.340 that resulted in a crash when using file watchers (
--watch
option). - Fixed regression introduced in 1.1.340 that resulted in incorrect import resolution for certain namespace packages.
- Fixed bug that resulted in a false positive error when one ParamSpec was captured by another ParamSpec.
- Fixed bug related to function type compatibility when the dest type contains an unpacked tuple followed by one or more positional-only parameters as in
Callable[[*Ts, int], None]
.
Enhancements:
- Improved signature help provider so it handles overloaded
__init__
and__new__
methods when calling a constructor. - Updated typeshed stubs to the latest version.
Published 1.1.340
Bug Fixes:
- Fixed English text for position-only error. It contained an extraneous
\"
at the end. - Fixed a bug that resulted in a crash under certain circumstances when defining a type alias using a
type
statement when no type parameters are defined. - Fixed bug in narrowing logic for sequence pattern magic where special cases of
str
,bytes
, andbytearray
were not handled correctly. - Fixed bug that led to a false positive when a zero-argument form of
super
is called within an inner function or lambda. - Fixed a bug that led to a false positive error in certain cases involving a union of two callables.
- Removed implicit
__qualname__
attribute from the module namespace. It doesn't exist at runtime, so this was leading to a false negative. - Fixed bug that led to a false positive when a tuple of indeterminate length was used in a callback function.
- Fixed a bug that led to an improper "unbound" type evaluation under certain circumstances in a
finally
clause. - Fixed bug that results in an extraneous
}
character in stub output. - Fixed bug that led to incorrect return type inference for a generator that always raises an exception rather than returning.
- Fixed package manifest so default values of configurations are properly reflected.
Behavior Changes:
- (From pylance) All paths are now internally tracked as URIs. This provides better support for files that are not stored within a file system. This should be transparent to most pyright users.
- Previously, return type inference was disabled for all functions when
analyzeUnannotatedFunctions
was set to false regardless of whether the function had input type annotations. Return type inference is now enabled if the function is partially annotated.
Enhancements:
- Improved error message for
set
invariance type violations. - Added support for the
@warning.deprecated
(PEP 702) functionality when an overloaded function implementation is marked deprecated and then used outside of a call expression. - Enhanced type narrowing logic for sequence pattern matching to support narrowing of tuple subject types based on sequence subpatterns.
- Extended support for "partially unbound" variable detection to cases that involve comprehension and class scopes.
- Eliminated the limitation that unpack operators,
await
operators, assignment expressions (walrus operators), f-strings, chained strings, and strings with escape characters cannot be used withinAnnotated
expressions when using an alias ofAnnotated
.