Open DetachHead opened 2 months ago
To my understanding, this is caused by:
_
are treated as having an implicit type of Any
(per here).[1]
as a call to a hidden def [T] (*T) -> list[T]
function, where the type variable T
needs to be resolved using the ordinary type inference rules.Any
. This ultimately causes mypy to prematurely resolve the type of the list constructor from def [T] (*T) -> list[T]
to def (*Any) -> list[Any]
on this line. Hence [1]
is inferred to have type list[Any]
, cue the error.I think this is the same underlying issue as #14664. In both cases, mypy infers the type of a callable to something overly broad when a type context is present, and infers a stricter type when the type context is removed.
Possible duplicate of #15253
playground