You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Self as return type annotation in base class method breaks multi-inheritance #14640
For the record, the Collection class is not necessary to expose the problem:
fromtypingimportSelfclassBase1:
deffoo(self) ->Self:
returnselfclassBase2:
deffoo(self) ->Self:
returnselfclassSub(Base1, Base2): # error: Definition of "foo" in base class "Base1" is incompatible with definition in base class "Base2" [misc]pass
Activity
hauntsaninja commentedon Feb 7, 2023
I guess the issue is that the bounds are different?
uriyyo commentedon Feb 7, 2023
@hauntsaninja I guess code with
Selfshould cover all the cases whenTypeVarworkaround was used.So if this code works as expected:
Then the code below should work too:
I didn't find anything related to this in PEP 673, but
pyrighthandle such case and works as I expected.Please, correct me if I missed smth.
srittau commentedon Oct 13, 2024
For the record, the
Collectionclass is not necessary to expose the problem:(mypy 1.11.2)
Real-life example: python/typeshed#12788, where peewee makes use of that pattern.
sterliakov commentedon Jan 16, 2025
@hauntsaninja this is one more ticket resolved by #18465 - sorry again, I should have searched for them more thoroughly:(
hauntsaninja commentedon Jan 16, 2025
No need to apologise, thank you for fixing so many things!