J
Jp Calderone
Due to some bizarre constraints placed on me, I've written the following
metaclass:
import types
def remove(t, o):
return tuple([e for e in t if t not in o])
class BizarreMetaclass(type):
def __new__(klass, name, bases, attrs):
if name == 'BaseClass':
return type.__new__(klass, name, bases, attrs)
return types.ClassType(name, remove(bases, [object]), attrs)
class BaseClass(object):
__metaclass__ = BizarreMetaclass
class Foo(BaseClass):
pass
The solution is extremely hacky (but I've already tried and discarded
about a dozen more straightforward attempted solutions).
It is also broken, but it is broken in a way that I do not understand.
Can anyone explain the unbounded recursion that occurs?
Jp
metaclass:
import types
def remove(t, o):
return tuple([e for e in t if t not in o])
class BizarreMetaclass(type):
def __new__(klass, name, bases, attrs):
if name == 'BaseClass':
return type.__new__(klass, name, bases, attrs)
return types.ClassType(name, remove(bases, [object]), attrs)
class BaseClass(object):
__metaclass__ = BizarreMetaclass
class Foo(BaseClass):
pass
The solution is extremely hacky (but I've already tried and discarded
about a dozen more straightforward attempted solutions).
It is also broken, but it is broken in a way that I do not understand.
Can anyone explain the unbounded recursion that occurs?
Jp