Difference: JythonUpgrade (1 vs. 10)

Revision 102012-10-19 - DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="WebHome"
Added:
>
>
<-- ANALYTICS CODE - DO NOT EDIT -->
<-- Google Analytics script BEGIN -->
<-- Google Analytics script END -->

<-- END OF ANALYTICS CODE -->
 

Upgrade to Jython 2.5

Up to HIPE 7, we have been using the Jython 2.1 library, which mostly uses the syntax of Python 2.1

Line: 155 to 158
 
<--  
-->
\ No newline at end of file
Added:
>
>
META FILEATTACHMENT attachment="GoogleAnalytics.txt" attr="h" comment="Script for Google Analytics" date="1350657378" name="GoogleAnalytics.txt" path="GoogleAnalytics.txt" size="549" stream="GoogleAnalytics.txt" user="Main.DavideRizzo" version="1"

Revision 92012-05-14 - DavideRizzo

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Upgrade to Jython 2.5

Line: 135 to 135
 
Added:
>
>

<-- COMMENT BOX CODE - DO NOT EDIT -->
blog comments powered by Disqus
<-- END OF COMMENT BOX CODE -->

 
<--  
-->

Revision 82011-12-14 - JaimeSaiz

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Upgrade to Jython 2.5

Line: 45 to 45
 

Fix 2: make import statement specific

Deleted:
<
<
Alternatively, you can make the import statement specific:
 

Deleted:
<
<
 : def foo(): from herschel.ia.foo.banana import SomeThing
Line: 90 to 88
 
Changed:
<
<
TODO (verify): If you always want the full name, use: Bar.getFastName()
>
>
If you always want the full name, use: Bar.canonicalName
 

Revision 72011-11-18 - JorgoBakker

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Upgrade to Jython 2.5

Deleted:
<
<

 Up to HIPE 7, we have been using the Jython 2.1 library, which mostly uses the syntax of Python 2.1
Starting from HIPE 8 we will upgrade to Jython 2.5, which uses the same syntax rules as Python 2.5.

In most cases, your scripts will run fine; however, in certain cases you may need to adapt them. This page lists the known differences between Jython 2.1 and Jython 2.5

Added:
>
>

 

Wrong locations of global import statements

Changed:
<
<
You may have written code where global import statements are done within a Jython function.
>
>
You may have written code where global import statements are done within a Jython function.
 As of Jython 2.5, this is not allowed anymore (in fact, it was not allowed in Python 2.1 but Jython 2.1 inadvertently allowed for it).

When executing the code against Jython 2.5, you will get messages such as:

Line: 59 to 59
 

Known jython module changes

Added:
>
>
The following modules changed their names:
 
Jython 2.1 Jython 2.5
import javaos import os

Known jython behavioral changes

Added:
>
>
 

__name__


Line: 89 to 92
 

TODO (verify): If you always want the full name, use: Bar.getFastName()

Added:
>
>
 

Numeric types

Added:
>
>
  In Jython 2.1 numeric types were Py objects like PyInteger or PyFloat and as such had methods like toString(). In Jython 2.5 numeric types are more like native types and do not have these basic Object methods available. The difference was discovered when passing an integer into a jython function and then printing this value using the toString() method. In Jython 2.5 this results in the following error:
  <type 'exceptions.AttributeError'>: 'int' object has no attribute 'toString'
Line: 131 to 136
 
  • Add a float literal to the expression ( + 0.0 )
  • Use an explicit cast to float (float(i))
Added:
>
>
 

Revision 62011-08-30 - JavierDiaz

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Upgrade to Jython 2.5

Line: 104 to 104
 foo = 3.141500
Added:
>
>
Some other Java methods can no longer be applied to numbers (which may require changing some client code). In general, when using Jython we should just use Jython functionality if available to avoid this type of problems. The following example shows what happens when you try to move from "long" to "double" using java.lang.Number methods (to make a floating point division for example).
 
Added:
>
>
This works with Jython 2.1:
HIPE> i = 3L
HIPE> print i.__class__
org.python.core.PyLong
HIPE> d = i.doubleValue()
HIPE> print d
3.0
While it no longer works with Jython 2.5 (HIPE 8):
HIPE> i = 3L
HIPE> print i.__class__
<type 'long'>
HIPE> d = i.doubleValue()
<type 'exceptions.AttributeError'>: 'long' object has no attribute 'doubleValue'
HIPE> print d
<type 'exceptions.NameError'>: name 'd' is not defined

In this particular case the following alternatives can be used to promote to floating point:

  • Add a float literal to the expression ( + 0.0 )
  • Use an explicit cast to float (float(i))
 

Revision 52011-05-13 - JaimeSaiz

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Upgrade to Jython 2.5

Line: 72 to 72
 Bar #Jython 2.1: foo.Bar
Added:
>
>
$ print Bar.__module__ foo

$ print Bar.__module__ + "." + Bar.__name__ foo.Bar

$ print Bar.name # if Bar is a Java class foo.Bar

 $ import foo.Bar $ print foo.Bar.__name__ foo.Bar

Revision 42011-05-13 - RikHuygen

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Upgrade to Jython 2.5

Line: 80 to 80
 TODO (verify): If you always want the full name, use: Bar.getFastName()
Added:
>
>

Numeric types

In Jython 2.1 numeric types were Py objects like PyInteger or PyFloat and as such had methods like toString(). In Jython 2.5 numeric types are more like native types and do not have these basic Object methods available. The difference was discovered when passing an integer into a jython function and then printing this value using the toString() method. In Jython 2.5 this results in the following error:

  <type 'exceptions.AttributeError'>: 'int' object has no attribute 'toString'
The solution is very simple and is also recommended to use in all Jython versions, i.e. replace the toString() with a format string, for example:
HIPE> foo = 3.1415
HIPE> print "foo =", foo.toString()  # DO NOT USE THIS !!
HIPE> print "foo = %f" % foo
foo = 3.141500
 

Revision 32011-05-02 - JorgoBakker

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Upgrade to Jython 2.5

Line: 63 to 63
 
import javaos import os
Added:
>
>

Known jython behavioral changes

__name__

$ from foo import Bar
$ print Bar.__name__
Bar
#Jython 2.1: foo.Bar

$ import foo.Bar
$ print foo.Bar.__name__
foo.Bar

TODO (verify): If you always want the full name, use: Bar.getFastName()

 

Revision 22011-05-02 - JorgoBakker

Line: 1 to 1
 
META TOPICPARENT name="WebHome"

Upgrade to Jython 2.5

Line: 12 to 12
 This page lists the known differences between Jython 2.1 and Jython 2.5

Wrong locations of global import statements

Changed:
<
<
You may have written code where global import statements are done within a Jython function.
>
>
You may have written code where global import statements are done within a Jython function.
 As of Jython 2.5, this is not allowed anymore (in fact, it was not allowed in Python 2.1 but Jython 2.1 inadvertently allowed for it).

When executing the code against Jython 2.5, you will get messages such as:

Line: 58 to 57
 
Added:
>
>

Known jython module changes

Jython 2.1
<-- -->
Sorted ascending
Jython 2.5
import javaos import os
 

Revision 12011-04-18 - DavideRizzo

Line: 1 to 1
Added:
>
>
META TOPICPARENT name="WebHome"

Upgrade to Jython 2.5


Up to HIPE 7, we have been using the Jython 2.1 library, which mostly uses the syntax of Python 2.1
Starting from HIPE 8 we will upgrade to Jython 2.5, which uses the same syntax rules as Python 2.5.

In most cases, your scripts will run fine; however, in certain cases you may need to adapt them. This page lists the known differences between Jython 2.1 and Jython 2.5

Wrong locations of global import statements

You may have written code where global import statements are done within a Jython function. As of Jython 2.5, this is not allowed anymore (in fact, it was not allowed in Python 2.1 but Jython 2.1 inadvertently allowed for it).

When executing the code against Jython 2.5, you will get messages such as:

SyntaxWarning: import * only allowed at module level

To fix your code, you have two options:

  • Move the global import statement out of the function and to the top of your script.
  • Make the import statement specific.

See below for examples of fixes to incorrect code.

Current: wrong use of global import

:
def foo():
    from herschel.ia.foo.banana import * # global import statement, to access SomeThing
    x=SomeThing()
    return

Fix 1: global import statement at start of script

from herschel.ia.foo.banana import *
:
def foo():
    x=SomeThing()
    return

Fix 2: make import statement specific

Alternatively, you can make the import statement specific:

:
def foo():
    from herschel.ia.foo.banana import SomeThing
    x=SomeThing()
    return

<--  
-->
 
This site is powered by the TWiki collaboration platform Powered by Perl