Closed
Description
Now that we have a central stub for common types and protocols, we should think about how we name protocols in typeshed. Currently there is no common convention. Some possible conventions for a "read" protocol:
Readable
HasRead
SupportsRead
IsReadable
Reader
I have no strong preferences, but I think the naming to reflect that a class is a protocol. Therefore I'd suggest we should use either, some, or all of the above. The second name (HasRead
) clearly implies the existence of a field read
, but would exclude protocols with multiple fields, such as this from stdlib/3.9/zoneinfo/__init__.pyi
:
class _IOBytes(Protocol):
def read(self, __size: int) -> bytes: ...
def seek(self, __size: int, __whence: int = ...) -> Any: ...
Here is a proposal to start the discussion:
- Use plain names for protocols that represent a clear concept (e.g.
Iterator
,Container
). - Use
SupportsX
for protocols that provide type conversion (e.g.SupportsInt
). - Use
Xable
for protocols that provide callable methods (e.g.Readable
,LineReadable
,BytesReadable
,ReadSeekable
). - Use
HasX
for protocols that have readable and/or writable attributes or getter/setter methods (e.g.HasItems
,HasFileno
).