Skip to content

Should we use _ProtocolMeta in typing.py? #8998

@sobolevn

Description

@sobolevn

Right now _ProtocolMeta is never used:

class _ProtocolMeta(ABCMeta): ...

But, it is a base metaclass for Protocol type in typing.py: https://github.com/python/cpython/blame/723ebe76e787cfa6b08cc9587dd679f3234a1025/Lib/typing.py#L1965

It is also used for all Protocol types (we currently just use ABCMeta for them`):

typeshed/stdlib/typing.pyi

Lines 287 to 305 in 739711e

@runtime_checkable
class SupportsInt(Protocol, metaclass=ABCMeta):
@abstractmethod
def __int__(self) -> int: ...
@runtime_checkable
class SupportsFloat(Protocol, metaclass=ABCMeta):
@abstractmethod
def __float__(self) -> float: ...
@runtime_checkable
class SupportsComplex(Protocol, metaclass=ABCMeta):
@abstractmethod
def __complex__(self) -> complex: ...
@runtime_checkable
class SupportsBytes(Protocol, metaclass=ABCMeta):
@abstractmethod
def __bytes__(self) -> bytes: ...

CPython: https://github.com/python/cpython/blame/723ebe76e787cfa6b08cc9587dd679f3234a1025/Lib/typing.py#L2745

So, the question is:

  1. Should we use for Protocol class? It is rather complex, because right now Protocol is _SpecialForm
  2. Should we use it for Protocol types in typing.pyi?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions