Bot releases are visible (Hide)
Published by bschnurr 25 days ago
Bug Fixes:
type
is used within a loop.Final
variable in a protocol and a NamedTuple or frozen dataclass as a concrete class.Never
to a type variable in a contravariant context.TypeForm
as the second argument to an isinstance
or issubclass
call.TypeForm
is used as the first argument to isinstance
.__call__
method and a __new__
or __init__
method that provides a different bidirectional type inference context for parameters.Enhancements:
len(t) == L
type guard pattern to handle the negative narrowing case where tuple t
has a minimum length of L
. In this case, the narrowed type can be computed whereas previously it was left unnarrowed.reportUnnecessaryComparison
to cover more cases involving is
and is not
operators.Published by bschnurr about 1 month ago
Bug Fixes:
type(Any)
to type type[Any]
.TypeIs
user-defined type guard in certain cases when variable type is a union.isinstance
in the negative case when using type
as a filter.NoReturn
callable with a function decorator applied.TypeIs
intersects type[A]
with type[B]
. Previously, pyright was producing <subclass of type[A] and type[B]>
but now produces type[<subclass of A and B>]
.venvPath
specified in language server settings to be ignored.__set__
method when assigning to a class variable that is not a descriptor object.Self
in its type definition.Behavior Changes:
TypeForm
based on feedback to draft PEP 747.Enhancements:
reportUnnecessaryIsinstance
check to report cases where an isinstance
or issubclass
call always evaluates to False
.Bug Fixes:
super()
and the second argument is type[Self]
.defaultdict
) to a callable type.match
statement.--verifytypes
and the function has a decorator applied that uses a ParamSpec.isinstance
or TypeIs
when the filter type (the second argument to isinstance
) is a subclass of type
.in
(containment) operator when the filter includes class objects (instances of type
).x is ...
(ellipsis) type guard pattern.TypeAlias
qualifier.TypeIs
when it is used with a Callable
type form.isinstance
type narrowing code involving callablesEnhancements:
ABCMeta
. Classes instantiated from such metaclasses are now treated as abstract.Behavior Changes:
**
) when used in an argument expression for a call and the operand is a TypedDict. It now takes into account the fact that a (non-closed) TypedDict can contain additional keys with object
values. This new behavior is consistent with mypy.Never
._AnnotatedAlias
to be used with an implicit __getitem__
call even though this type is not documented or declared in typeshed.from __future__
import statement, which has no meaning in stub files.callable
type guard pattern. Now that typeshed defines this with a TypeIs
, we no longer require custom logic here.Published by bschnurr about 2 months ago
Bug Fixes:
Callable
special form is used in a value expression.Enhancements:
TypeForm
special form.Published by github-actions[bot] about 2 months ago
Bug Fixes:
functools.partial
in some cases. This same issue also causes symbols accessed in these arg expressions to not be marked as referenced.__call__
method whose cls
parameter is annotated with type[T]
.reportIncompatibleMethodOverride
diagnostic being reported in the wrong location in some cases involving decorators.Behavior Changes:
disableBytesTypePromotions
setting from false
to true
. It has been over two years since PEP 688 was accepted, so it's time for us to stop treating bytes
as an alias for bytes | bytearray | memoryview
. This is a breaking change and may require an update to the pyright configuration for some code bases.Published by github-actions[bot] about 2 months ago
Bug Fixes:
TypeGuard[T]
or TypeIs[T]
to a supertype of bool
(like int
).--pythonversion
and --threads
CLI options are used together.Enhancements:
__init__
methods in dataclasses). This allows the original default value expression to be printed in error messages and language server strings.Published by github-actions[bot] 2 months ago
Bug Fixes:
Literal
doesn't follow type expression rules within a value expression context.reportIncompatibleMethodOverride
when the child class method uses a type parameter that is scoped to the child class.reportSelfClsParameterName
check. Previously, different rules were applied to __new__
and class methods within metaclasses.isinstance
type narrowing between a type
and another type creates a subclass.isinstance
type narrowing between a type
and another type creates a subclass.Enhancements:
Behavior Changes:
__lt__
, etc.) for dataclasses when order=True
to use Self
rather than an instance of the class. This is not only more consistent with other synthesized methods, but it also preserves covariance of type variables if the dataclass is frozen.Published by github-actions[bot] 2 months ago
Bug Fixes:
Unknown
types that include type aliases.functools.partial
logic that results in incorrect handling of an unpacked TypedDict when used with a **kwargs
parameter.reportUnsupportedDunderAll
warning when using the __all__.extend(x.__all__)
form and the list of entries in x
is empty.IntEnum
and StrEnum
members. These literal values are subtypes of the corresponding literal int
or str
.cast
method on memoryview
object to be treated as a type expression. Pyright was confusing this method with typing.cast
.*args
(variadic) parameter.__bool__
call to the underlying value.isinstance
with an instance of a generic class as the first argument and a concrete subclass as the filter type.Enhancements:
bool
expansion to Literal[True] | Literal[False]
during pattern matching when using value patterns.Behavior Changes:
disableLanguageServices
feature to apply to hover text as well as other language services. Previously, hover text was excluded.Final
and ClassVar
to be combined in both directions within a dataclass. Previously, the Final
qualifier needed to be the outermost.Published by github-actions[bot] 3 months ago
Note: This week's release includes some major changes related to TypeVar constraint solving that have been in the works for a while. These changes simplify the code, make constraint solving behaviors more consistent, and eliminate a number of false positive errors that were reported over the past year. However, these code changes produce different constraint solving behaviors in some cases. These extensive code changes also come with the potential of regressions. I've done extensive analysis of the type checking outputs across over a hundred public code bases, but it's possible that I've missed something. Please report any new behavior that you think is a bug.
Bug Fixes:
TypeIs[T]
, TypeGuard[T]
and bool
when used in a return type of a callable.Optional
is used with no subscript (i.e. Optional[]
).isinstance
type narrowing if the second argument is object
and the first argument is a type
instance.isinstance
type narrowing when the filter class and the type are both protocols.self
parameter in an __init__
method is given an explicit Self
annotation.__iter__
method.TypeIs
or TypeGuard
and the implementation returns bool
.TypeIs
.isinstance
type narrowing results in an intersection type.__set__
descriptor method is marked deprecated and is implicitly accessed using an augmented assignment operator, as in a.x += 1
.None
.__init__
or __new__
method parameters.super()
outside of a class.Enhancements:
__init__
or __new__
signature with a mechanism that uses the recently-ratified typing spec algorithm for converting a constructor into a callable. This is prompted in part by this discussion.Final
attribute. This should be considered invalid.enableReachabilityAnalysis
. It is off by default when typeCheckingMode
is "off" but otherwise on by default. When disabled, it causes pyright not to identify code blocks that are determined to be unreachable via type analysis. Code blocks that are determined to be unreachable via non-type information are still displayed as such.Final
variable assigned in a loop.@deprecated
decorator on magic methods for unary and binary operations.@deprecated
on __bool__
magic method used by not
operator.@deprecated
on __new__
methods used implicitly during a class constructor call.Other Changes:
list[1 + 2]
) if the expression is a value expression.T is None
type narrowing logic to handle TypeVars with no bounds better. The previous logic was arguably correct, but it produced results that were unexpected by some users.T
over type[T
]` when both are valid.Published by github-actions[bot] 3 months ago
Bug Fixes:
Annotated
type is used in a type argument within a specialized type on the LHS of a call expression, such as list[Annotated[int, ""]]()
.TypeIs
form when the return type of the type guard function is a specialized generic class.reportInconsistentConstructor
. It produced false negatives in some cases and produced bad error messages in other cases.Behavior Changes:
Enhancements:
__extra_types__
in a closed TypedDict.__replace__
method in dataclass and namedtuple classes, a new feature in Python 3.13.Published by github-actions[bot] 3 months ago
Bug Fixes:
isinstance
or issubclass
call.Unknown
rather than the unpacked TypeVarTuple.typing.Request
is used in an annotation expression.reportInconsistentConstructor
errors if one or both of __init__
or __new__
are overloaded.reportOverlappingOverload
error in certain cases involving ParamSpec
and Concatenate
.__init__.py
file in it. In this case, the ".py" file should take precedence during imports.or
or and
operator when the LHS evaluates to a literal int
, str
, bytes
or bool
type.type[T]
when T
evaluates to Any
.__init_subclass__
method under certain circumstances.Enhancements:
@member
and @nonmember
decorators.Behavior Changes:
Literal[1] | int
. Retaining these redundant subtypes can be useful for language server features like completion suggestions.__doc__
attribute for a module to always be str | None
. Previously, pyright changed its declared type to str
if a docstring was present in the module, but this is incorrect because it's a writable value and can be set to None
.Never
as a type argument for a value-constrained type parameter if Never
is an explicit constraint.Published by github-actions[bot] 3 months ago
Bug Fixes:
isinstance
or issubclass
call.type
as a base class in a class
statement.list
or set
expression includes more than 64 elements and is being evaluated with a bidirectional inference context.__init_subclass__
has overloads.Behavior Changes:
__class__
symbol to be Self@T
rather than T
(where T
is the enclosing class).Enhancements:
--threads
followed by an optional thread count. If no count is specified, pyright will use a value equal to the number of logical processors. Experimentation shows that this can speed up type checking by 2x to 3x for larger code bases. It has little or no effect (and possibly negative effects) for small code bases.dict[()]
.Published by github-actions[bot] 4 months ago
Bug Fixes:
tuple[Never]
.isinstance
or issubclass
type narrowing when using a type variable with an upper bound that includes a promotion type.type()
is called with dynamic base classes.NotImplementedError
.reportInconsistentOverload
and reportNoOverloadImplementation
errors when an overloaded decorator is applied to a non-overloaded function or method.[tools.pyright]
section in it.TypeAlias
definition.<class>
is a specific class T, as opposed to a variable of type type[T]
.NewType
and the new type is constructed.*tuple[Any, ...]
, not *tuple[Any]
.Enhancements:
Published by github-actions[bot] 4 months ago
Behavior Changes:
if
or else
suites when the condition type was narrowed to Never
.type
syntax.Enhancements:
reportUninitializedInstanceVariable
check to handle dataclass variables that are initialized implicitly by the synthesized __init__
method.Bug Fixes:
reportUninitializedInstanceVariable
check relating to NamedTuple
instance variables.__index__
but the indexed object specifies that it requires int
.tuple[()]
in overloads.__set__
and __delete__
calls to a descriptor object.**
call argument.Published by github-actions[bot] 4 months ago
Bug Fixes:
warnings.deprecated
not to work if the python version is 3.13. This was caused by recent changes to typeshed stubs.type
(with no type argument) or type[Any]
to be treated as a possible descriptor object.__dataclass_fields__
for named tuples.stubPath
's default value in configuration schema.Callable()
in the negative (fall-through) case.Behavior Changes:
yield
or yield from
statements. The "yield type" (the first type argument to Generator
) is now inferred as Never
in this case rather than None
.TypeAliasType
rather than the expanded type alias type.Enhancements:
deprecated
objects that are instantiated prior to being used as a decorator. This allows for a factory usage pattern.Protocol
type argument that is not a type parameter. The runtime generates an exception for this condition.Published by github-actions[bot] 4 months ago
Bug Fixes:
__bool__
.reveal_type
is used in a loop.Final
annotation not to be honored when wrapped in an Annotated
annotation.Any
when converting a NewType
or dataclass constructor to a callable.Enhancements:
Annotated
annotation.except*
to enforce that exception class does not derive from BaseExceptionGroup
.Behavior Changes:
site_packages
.Published by github-actions[bot] 5 months ago
Bug Fixes:
x is E
type narrowing pattern where E
is an enum literal and x
is a supertype of E
like object
.Behavior Changes:
__new__
evaluation results in type evaluation errors. Previously, pyright skipped the __init__
evaluation in this case. It now proceeds to evaluate __init__
, potentially generating redundant errors.Enum
class body in a stub. These are now treated as non-member attributes rather than members. Typeshed stubs have been updated to conform to the new standard.Enhancements:
Published by github-actions[bot] 5 months ago
Bug Fixes:
value
attribute of a StrEnum
or IntEnum
class.*args: *tuple[T, *tuple[S, ...]]
.list(tuple())
.tuple
instance with unknown type arguments is assigned to a target symbol with a declared tuple
type.Final
class variable is assigned a value in the class body and reassigned a value in the __init__
method.Behavior Changes:
Enhancements:
-p
option on the command line.Published by github-actions[bot] 5 months ago
Bug Fixes:
super
call is an instance of a metaclass.*args
parameter and the second has a single positional+keyword parameter.TypeIs[type[T]]
.tuple
.P[P[T]]
).*args: *Ts
parameter is passed as an argument to itself.Behavior Changes:
Enum
subclasses that explicitly override value
or name
to avoid using the special-case logic for computing these types. This is done regardless of whether the class uses a custom metaclass.Literal
and various other special forms in a value expression.Enhancements:
ClassVar
and Final
can be used together to distinguish between a regular Final
instance variable and a ClassVar
that is also Final
.Literal
or unions when used in a value expression.Published by github-actions[bot] 5 months ago
Bug Fixes:
reportInvalidTypeForm
.reportUnnecessaryTypeIgnoreComment
check to not include the error code.reportPrivateUsage
error when a global or nonlocal binding is used within a class to access an outer-scoped variable.reportUnnecessaryComparison
when a variable is used in a conditional expression and its type is a union that includes a Coroutine
and a non-coroutine.deprecatedTypingAliases
deprecation for collections.abc.AbstractSet
due to a recent change in typeshed stubs.assert_type
failure when a class is parameterized by a ParamSpec with a default value.isinstance
or issubclass
type guard when the filter is a generic class whose type parameter has a default value.Behavior Changes:
type(Any)
or type(x)
where x
is a value of type Any
or Unknown
. These now evaluate to type[Unknown]
.