Skip to content

Should we use _ProtocolMeta in typing.py? #8998

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`):

@runtime_checkable
classSupportsInt(Protocol, metaclass=ABCMeta):
@abstractmethod
def__int__(self) ->int: ...
@runtime_checkable
classSupportsFloat(Protocol, metaclass=ABCMeta):
@abstractmethod
def__float__(self) ->float: ...
@runtime_checkable
classSupportsComplex(Protocol, metaclass=ABCMeta):
@abstractmethod
def__complex__(self) ->complex: ...
@runtime_checkable
classSupportsBytes(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