Ah, these classes expect to get an additional first argument with the token from the parser, to get line number information and such things. I think fixing this on Franks ToDo-list. However it looks like the modified _ast module got you at least part of the way. The main problem I see with this solution is that isinstance-checks will not work, that might be important, so we will probably want to fix that.

Anyway, I think these further issues will be resolved soon, but it might take up to a week.


On Sun, Nov 9, 2008 at 2:53 AM, Ondrej Certik <ondrej@certik.cz> wrote:
Hi Tobias!

On Sun, Nov 9, 2008 at 2:20 AM, Tobias Ivarsson <thobes@gmail.com> wrote:
> Hi,
> These objects [1] are constants in Jython, but they seem to be classes in
> CPython.
> We could have them be factory functions returning the constants, but that
> would still meen that:
> Jython: >>> ast.Load() == ast.Load()
> CPython: >>> ast.Load() != ast.Load()
> is that an acceptable deviation? If it is then this could be easily fixed by
> modifying the Jython _ast.py.
> How does it work if you replace Lib/_ast.py with the patched version I have
> attached with this e-mail before compiling Jython? If that works I can clean
> it up a bit and check it in.

I tried that, unfortunately, it doesn't. Attached find a pure python
script (with no external dependecies) that reproduces the problem.


$ python2.6 ast_test.py
<__main__.Integer object at 0xb7bcf96c>
<__main__.Div object at 0xb7bcfbac>
<__main__.Mul object at 0xb7bcfbec>

jython (compiled with our _ast.py)

$ jython ast_test.py
Traceback (most recent call last):
 File "ast_test.py", line 79, in <module>
   print parse_expr("1", {})
 File "ast_test.py", line 75, in parse_expr
   a = Transform(local_dict, global_dict).visit(a)
 File "/home/ondra/repos/jython/dist/Lib/ast.py", line 256, in visit
   return visitor(node)
 File "/home/ondra/repos/jython/dist/Lib/ast.py", line 321, in generic_visit
   new_node = self.visit(old_value)
 File "/home/ondra/repos/jython/dist/Lib/ast.py", line 256, in visit
   return visitor(node)
 File "ast_test.py", line 36, in visit_Num
   return fix_missing_locations(Call(Name('Integer', Load()),
TypeError: org.python.antlr.ast.Name(): expected 3-4 args; got 2