basedpyright icon indicating copy to clipboard operation
basedpyright copied to clipboard

Research if the collections should be `Protocol`s or `ABC`s

Open KotlinIsland opened this issue 1 year ago • 19 comments

typing.pyi:

@runtime_checkable
class Iterable(Protocol[_T_co]):
    @abstractmethod
    def __iter__(self) -> Iterator[_T_co]: ...

_collections_abc.py:

class Iterable(metaclass=ABCMeta):

    __slots__ = ()

    @abstractmethod
    def __iter__(self):
        while False:
            yield None

    @classmethod
    def __subclasshook__(cls, C):
        if cls is Iterable:
            return _check_methods(C, "__iter__")
        return NotImplemented

while not being Protocols at runtime, they act like them, and they are both ABCMeta, so this is a fairly correct approximation

KotlinIsland avatar Apr 13 '24 01:04 KotlinIsland

related? https://github.com/microsoft/pyright/issues/6624

DetachHead avatar Apr 13 '24 01:04 DetachHead

#352 fixes the annoying reportMissingSuperCall errors on abstract methods, which makes me want to prioritize this as converting these to ABCs will make them far less annoying to work with. specifically AbstractContextManager.__enter__

DetachHead avatar May 09 '24 13:05 DetachHead

oh wait, it actually fixes that case too nvm

DetachHead avatar May 09 '24 13:05 DetachHead

oh wait, it actually fixes that case too nvm

no it doesnt, idiot

DetachHead avatar May 15 '24 11:05 DetachHead