Well, not exactly a "hack". It's perfectly valid python ... and like they say: One man's ugly is another man's elegance
Actually, there is another way to do this...
def myfunc():
if not 'depth' in myfunc.__dict__:
myfunc.depth = 0
myfunc.depth += 1
if myfunc.depth >50:
... test level < 50 and report/error
... do stuff
myfunc.depth -= 1
But, I think that is really ugly