__new__()
on a Generic
class doesn't work with Self
as return type if the typevar is not specified, picking the first element of the typevar
#15322
Labels
bug
mypy got something wrong
Bug Report
In
pandas-stubs
, we want to be able to returnSeries[int]
,Series[str]
, etc., as well as justSeries
from a__new__()
constructor. In the current released version, we had return types ofSeries[S1]
andSeries
and everything worked fine. But pyright made a change and developers there (@erictraut) say thatSelf
needs to be the return type. See discussion starting here: microsoft/pyright#5178 (comment)With that change,
mypy
has a strange behavior, where returningSelf
in an overload that doesn't specify the value of theGeneric
parameter picks the first value. in the list provided in theTypeVar
declaration.To Reproduce
Expected Behavior
Output from pyright:
Actual Behavior
The issue here is that the type of
f
should beFoo[Any]
, notFoo[int]
.Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: