[Python-3000] pyvm module - low level interface to Python's VM

Christian Heimes lists at cheimes.de
Fri Nov 30 11:35:18 CET 2007

Dirkjan Ochtman wrote:
> I don't know how hard it would be for Jython, IronPython et al. to 
> support this kind of interface, but seeing as how something like 
> zope.interface relies on it (and therefore all of Twisted, too, I 
> think), it's kind of mandatory anyway.

zope.interface could work without sys._getframe(). It's not mandatory
for its API. getframe is used for a clever hack which makes declaring
interfaces more convenient and readable.

class Example:

The implements() function uses frame inspection to find and modify the
local namespace of the class. The code looks like:

def implements(...):
    frame = sys._getframe(...)
    locals = frame.f_locals
    locals['someinterfacedata'] = ...

The same class and interface definition could be written as:

class Example:

implements(Example, IExample)

but it's not as readable as the version of implements() with stack


More information about the Python-3000 mailing list