[py-svn] py-trunk commit 4c1168157b73: hack around Jython's incorrect AST heriachy
commits-noreply at bitbucket.org
commits-noreply at bitbucket.org
Tue Oct 27 22:24:23 CET 2009
# HG changeset patch -- Bitbucket.org
# Project py-trunk
# URL http://bitbucket.org/hpk42/py-trunk/overview/
# User Benjamin Peterson <benjamin at python.org>
# Date 1256678566 18000
# Node ID 4c1168157b73f09eebe441f9011d217cf2b7c79b
# Parent 68c5479b8f72860ee9f5117388ab0471c019ab1c
hack around Jython's incorrect AST heriachy
--- a/_py/code/_assertionnew.py
+++ b/_py/code/_assertionnew.py
@@ -10,6 +10,29 @@ import py
from _py.code.assertion import _format_explanation, BuiltinAssertionError
+if sys.platform.startswith("java") and sys.version_info < (2, 5, 2):
+ # See http://bugs.jython.org/issue1497
+ _exprs = ("BoolOp", "BinOp", "UnaryOp", "Lambda", "IfExp", "Dict",
+ "ListComp", "GeneratorExp", "Yield", "Compare", "Call",
+ "Repr", "Num", "Str", "Attribute", "Subscript", "Name",
+ "List", "Tuple")
+ _stmts = ("FunctionDef", "ClassDef", "Return", "Delete", "Assign",
+ "AugAssign", "Print", "For", "While", "If", "With", "Raise",
+ "TryExcept", "TryFinally", "Assert", "Import", "ImportFrom",
+ "Exec", "Global", "Expr", "Pass", "Break", "Continue")
+ _expr_nodes = set(getattr(ast, name) for name in _exprs)
+ _stmt_nodes = set(getattr(ast, name) for name in _stmts)
+ def _is_ast_expr(node):
+ return node.__class__ in _expr_nodes
+ def _is_ast_stmt(node):
+ return node.__class__ in _stmt_nodes
+else:
+ def _is_ast_expr(node):
+ return isinstance(node, ast.expr)
+ def _is_ast_stmt(node):
+ return isinstance(node, ast.stmt)
+
+
class Failure(Exception):
"""Error found while interpreting AST."""
@@ -91,7 +114,7 @@ class DebugInterpreter(ast.NodeVisitor):
def generic_visit(self, node):
# Fallback when we don't have a special implementation.
- if isinstance(node, ast.expr):
+ if _is_ast_expr(node):
mod = ast.Expression(node)
co = self._compile(mod)
try:
@@ -100,7 +123,7 @@ class DebugInterpreter(ast.NodeVisitor):
raise Failure()
explanation = self.frame.repr(result)
return explanation, result
- elif isinstance(node, ast.stmt):
+ elif _is_ast_stmt(node):
mod = ast.Module([node])
co = self._compile(mod, "exec")
try:
More information about the pytest-commit
mailing list