Closed as not planned
Closed as not planned
Description
There are a few types in collection.abc
that subclass protocols but are not protocols themselves. For example Sequence
is a subclass of Collection
and Reversible
. It expects subclasses to implement __getitem__
and __len__
, the latter being a requirement of the Collection
protocol. I think that the stubs for these classes should explicitly subclass abc.ABC
so that typecheckers require implementation of all abstract methods when the @final
annotation is used.
Currently typecheckers disagree on how to handle these stubs. For this example mypy asks for __getitem__
and __len__
implementations and pyright throws no error:
from collections.abc import Sequence
from typing import final
@final
class Foo(Sequence[int]):
pass
bash-3.2$ mypy test.py
test.py:5: error: Final class test.Foo has abstract attributes "__getitem__", "__len__" [misc]
Found 1 error in 1 file (checked 1 source file)
bash-3.2$ pyright test.py
0 errors, 0 warnings, 0 informations
At runtime the types in collections.abc
are already abstract base classes:
>>> from collections.abc import Sequence
>>> Sequence.__class__
<class 'abc.ABCMeta'>