Issue1798
Created on 2011-09-22.13:17:21 by dturanski, last changed 2014-06-25.16:04:54 by zyasoft.
File name |
Uploaded |
Description |
Edit |
Remove |
JSR223Test.java
|
dturanski,
2011-09-22.13:17:20
|
Junit Test |
|
|
msg6649 (view) |
Author: David Turanski (dturanski) |
Date: 2011-09-22.13:17:20 |
|
I am not a python programmer, but this seems like a bug.
I would expect consistent behavior. As demonstrated by the test other languages support this. The test fails even if I explicitly reference the variable as in:
Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> x=7
>>> x
7
|
msg7778 (view) |
Author: Alan Kennedy (amak) |
Date: 2013-02-25.23:58:43 |
|
The fundamental issue here is that jython (identically to cpython) treats expressions differently from statements.
"eval" expects to receive an expression, and returns a value.
http://docs.python.org/2/library/functions.html#eval
"exec" expects to receive statements, and does not return a value.
http://docs.python.org/2/reference/simple_stmts.html#exec
JSR 223 is different: it treats has no "exec", and uses "eval" for both of the purposes that jython separates into "eval" and "exec".
Object eval(String script)
- Executes the specified script.
http://docs.oracle.com/javase/6/docs/api/javax/script/ScriptEngine.html#eval%28java.lang.String%29
Our implementation of JSR 223/javax.script is obviously missing this subtlety.
|
msg7779 (view) |
Author: Alan Kennedy (amak) |
Date: 2013-02-26.00:22:24 |
|
This is the part of the JSR specification that is missed in our JSR 223 implementation.
"""
SCR 4.2.1
In particular, the Scripting API does not distinguish between scripts
which return values and those which do not, nor do they make the
corresponding distinction between evaluating or executing scripts.
All scripts are executed using methods which returns an Object.
When scripts for which the interpreter returns no value are executed,
null is returned. Implementations using existing interpreters that use
different methods to execute different types of scripts must internally
determine which interpreter method to call.
"""
download.oracle.com/otn-pub/jcp/java_scripting-1.0-fr-eval-oth-JSpec/java_scripting-1_0-fr-spec.pdf
|
msg7780 (view) |
Author: Alan Kennedy (amak) |
Date: 2013-02-26.00:29:53 |
|
We need to be able to differentiate between statements and expressions before deciding whether to call "eval" or "exec" on the jython intepreter.
The ast.parse() function might be one way to do it
Jython 2.7b1+ (default:a30708945630, Feb 23 2013, 15:22:29)
[Java HotSpot(TM) Client VM (Sun Microsystems Inc.)] on java1.6.0_41
Type "help", "copyright", "credits" or "license" for more information.
>>> import ast
>>> ast.parse("x=7").body
[Assign]
>>> ast.parse("7").body
[Expr]
>>>
|
msg8714 (view) |
Author: Jim Baker (zyasoft) |
Date: 2014-06-19.05:42:41 |
|
My reading of "[w]hen scripts for which the interpreter returns no value are executed, null is returned" is that the current behavior is acceptable. Trying to do AST analysis to workaround this is going to be a challenging problem in the general case, even if it can be readily done for simple cases.
|
|
Date |
User |
Action |
Args |
2014-06-25 16:04:54 | zyasoft | set | status: pending -> closed |
2014-06-19 05:42:41 | zyasoft | set | status: open -> pending resolution: invalid messages:
+ msg8714 nosy:
+ zyasoft |
2013-02-26 00:29:53 | amak | set | messages:
+ msg7780 |
2013-02-26 00:22:24 | amak | set | messages:
+ msg7779 |
2013-02-25 23:58:43 | amak | set | messages:
+ msg7778 |
2013-02-25 19:42:03 | fwierzbicki | set | versions:
+ Jython 2.5, - 2.5.2 |
2013-02-25 19:28:52 | fwierzbicki | set | priority: normal nosy:
+ fwierzbicki |
2011-11-04 21:36:24 | amak | set | nosy:
+ amak |
2011-09-22 13:17:21 | dturanski | create | |
|