Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork1.9k
Open
Description
Currently, some dunder methods likeSequence.__getitem__
do not use positional-only arguments, which causes errors when trying to subclass with positional-only arguments. Therefore, dunder methods, especially operators like__getitem__
, that are typically not called using keyword arguments, should probably be annotated using positional only arguments in the stubs.
Code sample inpyright playground
fromtypingimportProtocol,Self,overload,LiteralclassSupportsSequenceGetitemA[T](Protocol):@overloaddef__getitem__(self,index:int)->T: ...@overloaddef__getitem__(self,index:slice)->"SupportsSequenceGetitemA[T]": ...classMySequenceA[T](SupportsSequenceGetitemA[T],Protocol):@overloaddef__getitem__(self,index:int,/)->T: ...@overloaddef__getitem__(self,index:slice,/)->Self: ...# ❌classSupportsSequenceGetitemB[T](Protocol):@overloaddef__getitem__(self,index:int,/)->T: ...@overloaddef__getitem__(self,index:slice,/)->"SupportsSequenceGetitemB[T]": ...classMySequenceB[T](SupportsSequenceGetitemB[T],Protocol):@overloaddef__getitem__(self,index:int,/)->T: ...@overloaddef__getitem__(self,index:slice,/)->Self: ...# ✅