From 77a7d576ec83995c106bc693e13c9c13aa812ab7 Mon Sep 17 00:00:00 2001 From: holger krekel Date: Thu, 10 Jun 2010 10:56:14 +0200 Subject: [PATCH] defer a number of other compiles to frame.eval (patch from Amaury on trunk/pypy fork, thanks) --HG-- branch : trunk --- CHANGELOG | 4 ++- py/_code/_assertionold.py | 52 +++++++++++++++++++-------------------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 5e8561c44..704d6f292 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -37,10 +37,12 @@ Bug fixes / Maintenance - fix issue105 assignment on the same line as a failing assertion - fix issue104 proper escaping for test names in junitxml plugin - fix issue57 -f|--looponfail to work with xpassing tests +- fix py.code.compile(source) to generate unique filenames +- fix assertion re-interp problems on PyPy, by defering code + compilation to the (overridable) Frame.eval class. - fix pyimport() to work with directories - streamline py.path.local.mkdtemp implementation and usage - don't print empty lines when showing junitxml-filename -- fix py.code.compile(source) to generate unique filenames - add optional boolean ignore_errors parameter to py.path.local.remove - fix terminal writing on win32/python2.4 diff --git a/py/_code/_assertionold.py b/py/_code/_assertionold.py index e37b536a4..a472b54b4 100644 --- a/py/_code/_assertionold.py +++ b/py/_code/_assertionold.py @@ -138,28 +138,28 @@ class Name(Interpretable): __view__ = ast.Name def is_local(self, frame): - co = compile('%r in locals() is not globals()' % self.name, '?', 'eval') + source = '%r in locals() is not globals()' % self.name try: - return frame.is_true(frame.eval(co)) + return frame.is_true(frame.eval(source)) except passthroughex: raise except: return False def is_global(self, frame): - co = compile('%r in globals()' % self.name, '?', 'eval') + source = '%r in globals()' % self.name try: - return frame.is_true(frame.eval(co)) + return frame.is_true(frame.eval(source)) except passthroughex: raise except: return False def is_builtin(self, frame): - co = compile('%r not in locals() and %r not in globals()' % ( - self.name, self.name), '?', 'eval') + source = '%r not in locals() and %r not in globals()' % ( + self.name, self.name) try: - return frame.is_true(frame.eval(co)) + return frame.is_true(frame.eval(source)) except passthroughex: raise except: @@ -187,8 +187,9 @@ class Compare(Interpretable): expr.explanation, operation, expr2.explanation) source = "__exprinfo_left %s __exprinfo_right" % operation try: - self.result = frame.eval(source, __exprinfo_left=expr.result, - __exprinfo_right=expr2.result) + self.result = frame.eval(source, + __exprinfo_left=expr.result, + __exprinfo_right=expr2.result) except passthroughex: raise except: @@ -234,14 +235,14 @@ for astclass, astpattern in { class UnaryArith(Interpretable): __view__ = astclass - def eval(self, frame, astpattern=astpattern, - co=compile(astpattern, '?', 'eval')): + def eval(self, frame, astpattern=astpattern): expr = Interpretable(self.expr) expr.eval(frame) self.explanation = astpattern.replace('__exprinfo_expr', expr.explanation) try: - self.result = frame.eval(co, __exprinfo_expr=expr.result) + self.result = frame.eval(astpattern, + __exprinfo_expr=expr.result) except passthroughex: raise except: @@ -262,8 +263,7 @@ for astclass, astpattern in { class BinaryArith(Interpretable): __view__ = astclass - def eval(self, frame, astpattern=astpattern, - co=compile(astpattern, '?', 'eval')): + def eval(self, frame, astpattern=astpattern): left = Interpretable(self.left) left.eval(frame) right = Interpretable(self.right) @@ -272,8 +272,9 @@ for astclass, astpattern in { .replace('__exprinfo_left', left .explanation) .replace('__exprinfo_right', right.explanation)) try: - self.result = frame.eval(co, __exprinfo_left=left.result, - __exprinfo_right=right.result) + self.result = frame.eval(astpattern, + __exprinfo_left=left.result, + __exprinfo_right=right.result) except passthroughex: raise except: @@ -286,9 +287,10 @@ class CallFunc(Interpretable): __view__ = ast.CallFunc def is_bool(self, frame): - co = compile('isinstance(__exprinfo_value, bool)', '?', 'eval') + source = 'isinstance(__exprinfo_value, bool)' try: - return frame.is_true(frame.eval(co, __exprinfo_value=self.result)) + return frame.is_true(frame.eval(source, + __exprinfo_value=self.result)) except passthroughex: raise except: @@ -335,9 +337,8 @@ class CallFunc(Interpretable): if source.endswith(','): source = source[:-1] source += ')' - co = compile(source, '?', 'eval') try: - self.result = frame.eval(co, **vars) + self.result = frame.eval(source, **vars) except passthroughex: raise except: @@ -352,21 +353,20 @@ class Getattr(Interpretable): def eval(self, frame): expr = Interpretable(self.expr) expr.eval(frame) - co = compile('__exprinfo_expr.%s' % self.attrname, '?', 'eval') + source = '__exprinfo_expr.%s' % self.attrname try: - self.result = frame.eval(co, __exprinfo_expr=expr.result) + self.result = frame.eval(source, __exprinfo_expr=expr.result) except passthroughex: raise except: raise Failure(self) self.explanation = '%s.%s' % (expr.explanation, self.attrname) # if the attribute comes from the instance, its value is interesting - co = compile('hasattr(__exprinfo_expr, "__dict__") and ' - '%r in __exprinfo_expr.__dict__' % self.attrname, - '?', 'eval') + source = ('hasattr(__exprinfo_expr, "__dict__") and ' + '%r in __exprinfo_expr.__dict__' % self.attrname) try: from_instance = frame.is_true( - frame.eval(co, __exprinfo_expr=expr.result)) + frame.eval(source, __exprinfo_expr=expr.result)) except passthroughex: raise except: