Monday, November 21, 2011

metaclass depth > call depth

How far deep can a metaclass tree go?
type(A) = B, type(B) = C, type(C) = D...?
Can it go further than the function call depth?

def tower(n=100, sofar=type):
   class next(sofar):
      __metaclass__ = sofar
   return tower(n-1, next)

>>> tower(997)
<class '__main__.sofar'>
>>> tower(998)
#...
  File "<stdin>", line 3, in tower
RuntimeError: maximum recursion depth exceeded while calling a Python object

1 comment:

  1. Thanks for sharing such a Excellent Blog! We are linking too this particularly great post on our site. Keep up the great writing.
    python assignment help

    ReplyDelete