diff --git a/pony/orm/asttranslation.py b/pony/orm/asttranslation.py index 6c9068b60..e818e2d1f 100644 --- a/pony/orm/asttranslation.py +++ b/pony/orm/asttranslation.py @@ -362,12 +362,25 @@ def create_extractors(code_key, tree, globals, locals, special_functions, const_ for node in pretranslator.externals: src = node.src = ast2src(node) if src == '.0': - def extractor(globals, locals): - return locals['.0'] + extractor = Extractor('.0') else: code = compile(src, src, 'eval') - def extractor(globals, locals, code=code): - return eval(code, globals, locals) + extractor = Extractor(src, code) extractors[src] = extractor result = extractors_cache[code_key] = tree, extractors return result + + +class Extractor(object): + + def __init__(self, src, code=None): + self.src = src + self.code = code + + def __call__(self, globals, locals): + if self.src == '.0': + return locals['.0'] + return eval(self.code, globals, locals) + + def __repr__(self): + return 'Extractor(%s)' % self.src