MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / with_metaclass

Function with_metaclass

test/unified_format_shared.py:147–170  ·  view source on GitHub ↗

Create a base class with a metaclass. Vendored from six: https://github.com/benjaminp/six/blob/master/six.py

(meta, *bases)

Source from the content-addressed store, hash-verified

145
146
147def with_metaclass(meta, *bases):
148 """Create a base class with a metaclass.
149
150 Vendored from six: https://github.com/benjaminp/six/blob/master/six.py
151 """
152
153 # This requires a bit of explanation: the basic idea is to make a dummy
154 # metaclass for one level of class instantiation that replaces itself with
155 # the actual metaclass.
156 class metaclass(type):
157 def __new__(cls, name, this_bases, d):
158 # __orig_bases__ is required by PEP 560.
159 resolved_bases = types.resolve_bases(bases)
160 if resolved_bases is not bases:
161 d["__orig_bases__"] = bases
162 return meta(name, resolved_bases, d)
163
164 @classmethod
165 def __prepare__(
166 cls, name: str, this_bases: tuple[type, ...], /, **kwds: Any
167 ) -> MutableMapping[str, object]:
168 return meta.__prepare__(name, bases)
169
170 return type.__new__(metaclass, "temporary_class", (), {})
171
172
173def parse_collection_or_database_options(options):

Callers 2

SpecTestBaseClass · 0.90
SpecTestBaseClass · 0.90

Calls 1

__new__Method · 0.45

Tested by

no test coverage detected