MCPcopy Index your code
hub / github.com/python/cpython / __new__

Method __new__

Lib/typing.py:2016–2033  ·  view source on GitHub ↗
(mcls, name, bases, namespace, /, **kwargs)

Source from the content-addressed store, hash-verified

2014 # This metaclass is somewhat unfortunate,
2015 # but is necessary for several reasons...
2016 def __new__(mcls, name, bases, namespace, /, **kwargs):
2017 if name == "Protocol" and bases == (Generic,):
2018 pass
2019 elif Protocol in bases:
2020 for base in bases:
2021 if not (
2022 base in {object, Generic}
2023 or base.__name__ in _PROTO_ALLOWLIST.get(base.__module__, [])
2024 or (
2025 issubclass(base, Generic)
2026 and getattr(base, "_is_protocol", False)
2027 )
2028 ):
2029 raise TypeError(
2030 f"Protocols can only inherit from other protocols, "
2031 f"got {base!r}"
2032 )
2033 return super().__new__(mcls, name, bases, namespace, **kwargs)
2034
2035 def __init__(cls, *args, **kwargs):
2036 super().__init__(*args, **kwargs)

Callers

nothing calls this directly

Calls 3

superClass · 0.85
getMethod · 0.45
__new__Method · 0.45

Tested by

no test coverage detected