Releases: microsoft/pyright
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
awaitoperator within the left-mostfor. This shouldn't result in anAsyncGeneratordespite what the Python documentation indicates. - Fixed a bug in the
isinstancetype narrowing logic whentypeis filtered using a metaclass instance. - Fixed recent regression that resulted in a crash when using certain language server features with an absolute
extraPathsvalue. - 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
Callableis 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
Enumor 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
Annotatedand 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.memberandenum.nonmember. - Added new language server setting
pyright.disableTaggedHintsto 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
exceptstatement. - Fixed a bug that led to a false negative when using a non-data protocol class in a tuple within an
issubclasscheck. - Fixed a bug that resulted in incorrect inference of an async generator expression if an
awaitkeyword was used in aforiterator 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
Annotatedtype 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
NewTypewas 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 aLiteralStringsubject. - 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
selforclsparameter 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 inLiteralinttype 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
Annotatedtype 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
TypeVarTupleconstructor 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
@finalin 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
ClassVarin 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
Concatentatespecial form is used in an illegal context. - Added support for constants for field names in
NamedTuplecall. - 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
issubclasscall. PEP 544 indicates that this isn't allowed. - Added check for "unsafe overlaps" for a runtime-checkable protocol when used in an
issubclassorisinstancecheck.
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 ifuseExperimentalFeaturesis 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
typestatement 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
TypeAliasTypeconstructor. - 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
TypeAliasTypeconstructor 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
typestatement or a call toTypeAliasTypeis a valid type expression. - Added additional checks for invalid
NewTypecalls. - Improved detection of invalid type alias expressions for implicit (traditional) type aliases.
- Improved error reporting for
withstatement 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
Selfis used within a class definition statement. PEP 637 explicitly rejects this usage ofSelf. - Fixed a bug that leads to a false negative when
Selfis 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
TypedDictclass definition when using the normal class syntax. - Added detection of a call to
TypedDictalternative syntax form that assigns the resulting class to a variable whose name doesn't match the name specified in theTypedDictcall. - Added check for the use of a TypedDict class in an
isinstanceorissubclasscall. These generate a runtime exception.
Published 1.1.342
Bug Fixes:
- Fixed
@deprecatedfunctionality 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
--verifytypesCLI 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
Selfin 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
matchstatement 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
--verifytypesfunctionality. - 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
outputjsonoutput. - Fixed regression introduced in 1.1.340 that resulted in a crash when using file watchers (
--watchoption). - 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
typestatement when no type parameters are defined. - Fixed bug in narrowing logic for sequence pattern magic where special cases of
str,bytes, andbytearraywere not handled correctly. - Fixed bug that led to a false positive when a zero-argument form of
superis 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
finallyclause. - 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
analyzeUnannotatedFunctionswas 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
setinvariance 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,
awaitoperators, assignment expressions (walrus operators), f-strings, chained strings, and strings with escape characters cannot be used withinAnnotatedexpressions when using an alias ofAnnotated.
Published 1.1.339
Bug Fixes:
- Fixed a bug that resulted in a false positive error under certain circumstances involving inferred variance, decorators and generic type aliases.
- Fixed a bug that resulted in a false positive when
Selfwas used in a value expression outside of a class body. - Fixed bug that resulted in a false positive error when overriding a TypedDict field when the overridden type was
Anyor vice versa. - Fixed bug that resulted in a false negative when overriding a TypedDict field with an incompatible
RequiredorNotRequiredattribute. - Fixed recent regression that resulted in a false negative when
typeortype[Any]was used as a type annotation for a field in a dataclass. - Fixed a bug that results in a false positive when
anextis passed a value of typeAsyncIterator. - Fixed recent regression that results in false positive error where
typeortype[Any]is not considered type compatible withCallable. - Fixed bug that affected the case where a TypedDict class derived from two incompatible classes using multiple inheritance. The error was reported in the wrong location.
- Fixed bug that results in incorrect type evaluation when a
raisestatement is used within a context manager that swallows exceptions. - Fixed bug that led to incorrect type evaluation with unary operator when used with a type alias defined with forward references.
- Fixed bug that resulted in a crash within the function return type checking logic.
- Fixed bug that resulted in incorrect type evaluation when
delstatement is applied to a class member implemented with a descriptor. - Fixed regression that resulted in a false negative for the
reportUnknownMemberTypecheck when the expression is a call argument and the member is a function with a partially-unknown signature. - Fixed a bug that resulted in incorrect type evaluation in certain cases involving generic protocols and bound TypeVars.
- Fixed a bug in the code flow engine that resulted in a false negative for a variable whose type is narrowed within an inner loop.
- Fixed bug that led to improper type narrowing for class patterns when
Callableis used. - Fixed bug that resulted in incorrect narrowed type evaluation in certain circumstances involving certain code flow graph structures.
Enhancements:
- Added support in
dataclass_transformfor custom field specifiers that have default arguments for theirinitorkw_onlyparameters. - Implemented check for inconsistent use of
@staticmethodand@classmethodin overloads. - Added support for accessing members of a
TypeAliasTypeobject. - Added an error check for a PEP 695
typestatement within a function body. Type alias definitions are not allowed within this scope. - Added support for
*args: *Tsparameter that captures a callable with an indeterminate number of positional parameters because some of them have default arguments. - (Contribution from @jbarrachinab) Improved a few error messages in the Spanish localization.
- Enhanced support for TypeVarTuple capture of a callable to support literal arguments.
- Added a few optimizations that help improve perf somewhat when large unions are involved.
- Added support for doc strings when using the PEP 695
typestatement.
Behavior Changes:
- Added a new typeCheckingMode called "standard". It's a subset of "strict" but a superset of "basic". It is the new default mode, and it should cover all of the required checks for conformance with the Python typing standard.
- Changed behavior of check for unimplemented methods in a class that explicitly derives from a protocol. If the class also explicitly derives from
abc.ABC, it is exempted from this check. This is useful for mixin classes. - Changed behavior of
reportUnknownMemberType(and other checks in thereportUnknown...family) to not report a partially-unknown type if it refers to an unspecialized class. - Moved checks for Required/NotRequired and ReadOnly overrides from reportGeneralTypeIssue to reportIncompatibleVariableOverride for consistency. Added checks for Required/NotRequired and Readonly incompatibilities in the multiple inheritance case.
- Changed behavior of two-argument form of
superwhen it is used outside of an attribute access expression. It now employs a heuristic whereby it evaluates to the next base class of the bound type. - Changed the type printer logic to avoid emitting truncated
Literalstring and bytes values when it is asked to enforce Python syntax. This mode is used for inlay hints and the stub generator (for inferred return type comments).