Allocates space for a new class after altering its data.
(cls, name, bases, classdict, old=None)
| 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." |