Skip to content

Commit e734231

Browse files
typing: add _ProtocolMeta (#6394)
Co-authored-by: hauntsaninja <> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent df8472f commit e734231

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

stdlib/typing.pyi

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ if sys.version_info >= (3, 9):
122122
# Predefined type variables.
123123
AnyStr = TypeVar("AnyStr", str, bytes)
124124

125+
if sys.version_info >= (3, 8):
126+
# This class did actually exist in 3.7, but had a different base.
127+
# We'll just pretend it didn't exist though: the main external use case for _ProtocolMeta is
128+
# to inherit from for your own custom protocol metaclasses. If you're using 3.7, at runtime
129+
# you'd use typing_extensions.Protocol, which would be unrelated to typing._ProtocolMeta and
130+
# so you'd run into metaclass conflicts at runtime if you used typing._ProtocolMeta.
131+
class _ProtocolMeta(ABCMeta): ...
132+
125133
# Abstract base classes.
126134

127135
def runtime_checkable(cls: _TC) -> _TC: ...

stdlib/typing_extensions.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ Literal: _SpecialForm = ...
5353

5454
def IntVar(name: str) -> Any: ... # returns a new TypeVar
5555

56+
if sys.version_info < (3, 8):
57+
# Technically in 3.6 this inherited from GenericMeta. But let's not reflect that, since
58+
# type checkers tend to assume that Protocols all have the ABCMeta metaclass.
59+
class _ProtocolMeta(abc.ABCMeta): ...
60+
5661
# Internal mypy fallback type for all typed dicts (does not exist at runtime)
5762
class _TypedDict(Mapping[str, object], metaclass=abc.ABCMeta):
5863
__required_keys__: frozenset[str]

0 commit comments

Comments
 (0)