def _build_reserved_words(): class _SamuraiEmptyCommand(Command): pass Empty = _SamuraiEmptyCommand return frozenset(filter(lambda x: not is_python_reserved_attr(x), itertools.chain(Empty.__dict__.keys(), Empty().__dict__.keys(), Command.__dict__.keys()))) \ | frozenset(keyword.kwlist) \ | frozenset(("in", "out",))
def __new__(metacls, name, bases, namespace, **kwds): # Do not do anything for base class Command. if name == "Pool" and bases == (object,): return super().__new__(metacls, name, bases, namespace, **kwds) if Pool not in bases: raise TypeError("cannot subclass custom pool") ### Prepare namespace namespace.setdefault("depth", 1) for attrname in namespace.keys(): if is_python_reserved_attr(attrname): continue if attrname != "depth": raise TypeError("unknown attribute '{}' for Pool {}" .format(attrname, name)) depth = namespace["depth"] if not isinstance(depth, int): raise TypeError("depth must be an int") if depth < 1: raise ValueError("depth must be greater or equal to 1") ### Finally create the class. return super().__new__(metacls, name, bases, namespace, **kwds)