typing: add _ProtocolMeta (#6394)

Co-authored-by: hauntsaninja <>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
Shantanu
2021-11-27 06:53:36 -08:00
committed by GitHub
parent df8472f586
commit e734231314
2 changed files with 13 additions and 0 deletions

View File

@@ -122,6 +122,14 @@ if sys.version_info >= (3, 9):
# Predefined type variables.
AnyStr = TypeVar("AnyStr", str, bytes)
if sys.version_info >= (3, 8):
# This class did actually exist in 3.7, but had a different base.
# We'll just pretend it didn't exist though: the main external use case for _ProtocolMeta is
# to inherit from for your own custom protocol metaclasses. If you're using 3.7, at runtime
# you'd use typing_extensions.Protocol, which would be unrelated to typing._ProtocolMeta and
# so you'd run into metaclass conflicts at runtime if you used typing._ProtocolMeta.
class _ProtocolMeta(ABCMeta): ...
# Abstract base classes.
def runtime_checkable(cls: _TC) -> _TC: ...

View File

@@ -53,6 +53,11 @@ Literal: _SpecialForm = ...
def IntVar(name: str) -> Any: ... # returns a new TypeVar
if sys.version_info < (3, 8):
# Technically in 3.6 this inherited from GenericMeta. But let's not reflect that, since
# type checkers tend to assume that Protocols all have the ABCMeta metaclass.
class _ProtocolMeta(abc.ABCMeta): ...
# Internal mypy fallback type for all typed dicts (does not exist at runtime)
class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
__required_keys__: frozenset[str]