From: <fwi...@us...> - 2009-03-17 19:00:41
|
Revision: 6099 http://jython.svn.sourceforge.net/jython/?rev=6099&view=rev Author: fwierzbicki Date: 2009-03-17 19:00:26 +0000 (Tue, 17 Mar 2009) Log Message: ----------- Applied patch from http://bugs.jython.org/issue1148 to AstList to fix ClassCastException for slices. Also merged the test included in issue1148 into test_ast_jy.py with some small changes, especially the formatting to fit with pep 8 style. Thanks Geoffrey French (MrMeanie)! Modified Paths: -------------- trunk/jython/Lib/test/test_ast_jy.py trunk/jython/src/org/python/core/AstList.java Modified: trunk/jython/Lib/test/test_ast_jy.py =================================================================== --- trunk/jython/Lib/test/test_ast_jy.py 2009-03-17 02:59:34 UTC (rev 6098) +++ trunk/jython/Lib/test/test_ast_jy.py 2009-03-17 19:00:26 UTC (rev 6099) @@ -2,25 +2,40 @@ future""" import unittest +import ast from test import test_support -from ast import PyCF_ONLY_AST +def srcExprToTree(source, kind='exec'): + return compile(source, '<module>', kind, ast.PyCF_ONLY_AST) + class TestCompile(unittest.TestCase): def test_compile_ast(self): - node = compile("1/2", '<unknown>', 'exec', PyCF_ONLY_AST) + node = srcExprToTree("1/2") compile(node, "<string>", 'exec') def test_alias_trim(self): - node = compile("import os. path", '<unknown>', 'exec', PyCF_ONLY_AST) + node = srcExprToTree("import os. path") self.assertEquals(node.body[0].names[0].name, "os.path") - node = compile("import os .path", '<unknown>', 'exec', PyCF_ONLY_AST) + node = srcExprToTree("import os .path") self.assertEquals(node.body[0].names[0].name, "os.path") - node = compile("import os . path", '<unknown>', 'exec', PyCF_ONLY_AST) + node = srcExprToTree("import os . path") self.assertEquals(node.body[0].names[0].name, "os.path") + def test_cmpop(self): + expr = srcExprToTree('a < b < c', 'eval') + compare = expr.body + self.assert_(isinstance(compare.ops[0], ast.Lt)) + self.assert_(isinstance(compare.comparators[0], ast.Name)) + self.assert_(isinstance(compare.ops[1], ast.Lt)) + self.assert_(isinstance(compare.comparators[1], ast.Name)) + self.assert_(isinstance(compare.ops[1:][0], ast.Lt)) + self.assert_(isinstance(compare.comparators[1:][0], ast.Name)) + z = zip( compare.ops[1:], compare.comparators[1:]) + self.assert_(isinstance(z[0][0], ast.Lt)) + self.assert_(isinstance(z[0][1], ast.Name)) #============================================================================== Modified: trunk/jython/src/org/python/core/AstList.java =================================================================== --- trunk/jython/src/org/python/core/AstList.java 2009-03-17 02:59:34 UTC (rev 6098) +++ trunk/jython/src/org/python/core/AstList.java 2009-03-17 19:00:26 UTC (rev 6099) @@ -376,14 +376,14 @@ List newList = data.subList(start, stop); if(step == 1) { newList = data.subList(start, stop); - return new AstList(newList); + return new AstList(newList, adapter); } int j = 0; for(int i = start; j < n; i += step) { newList.set(j, data.get(i)); j++; } - return new AstList(newList); + return new AstList(newList, adapter); } public void insert(int index, PyObject o) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |