MCPcopy Create free account
hub / github.com/ActiveState/code / __new__

Method __new__

recipes/Python/578152_threadboxpy/recipe-578152.py:42–63  ·  view source on GitHub ↗

Allocates space for a new class after altering its data.

(cls, name, bases, classdict, old=None)

Source from the content-addressed store, hash-verified

40 return func
41
42 def __new__(cls, name, bases, classdict, old=None):
43 "Allocates space for a new class after altering its data."
44 assert '__new__' not in classdict, '__new__ must not be defined!'
45 assert '__slots__' not in classdict, '__slots__ must not be defined!'
46 assert '__module__' in classdict, '__module__ must be defined!'
47 valid = []
48 for base in bases:
49 if base in cls.__REGISTRY:
50 valid.append(cls.__REGISTRY[base])
51 elif base in cls.__REGISTRY.values():
52 valid.append(base)
53 else:
54 valid.append(cls.clone(base))
55 for key, value in classdict.items():
56 if callable(value) and (not hasattr(value, '_MetaBox__thread') or
57 value.__thread is not cls.__SENTINEL):
58 classdict[key] = cls.__wrap(value)
59 classdict.update({'__new__': cls.__new, '__slots__': (), '__module__':
60 '{}.{}'.format(__name__, classdict['__module__'])})
61 cls.__REGISTRY[object() if old is None else old] = new = \
62 super().__new__(cls, name, tuple(valid), classdict)
63 return new
64
65 def __init__(self, name, bases, classdict, old=None):
66 "Initializes class instance while ignoring the old class."

Callers 1

__newMethod · 0.45

Calls 8

__wrapMethod · 0.80
callableFunction · 0.50
appendMethod · 0.45
valuesMethod · 0.45
cloneMethod · 0.45
itemsMethod · 0.45
updateMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected