Release of JPype 1.0, libraries for accessing Java classes from Python

Available interlayer release JPype 1.0, which allows you to organize full access of Python applications to Java class libraries. With JPype from Python, you can use Java-specific libraries to create hybrid applications that combine Java and Python code. Unlike Jython, integration with Java is achieved not through the creation of a Python variant for the JVM, but through interaction at the level of both virtual machines using shared memory. The proposed approach allows not only to achieve good performance, but also provides access to all CPython and Java libraries. Project code spreads licensed under Apache 2.0.

Major changes:

  • JChar is supported as a return type. For compatibility, JChar is derived from "str" ​​and implements an implicit conversion to "int". Therefore, it passes checks in contracts. But this means that it is no longer considered a numeric type in Python, and so isinstance(c, int) evaluates to False, which is consistent with Java's type conversion rules.
  • An operator has been introduced to cast a Java type, Type@obj (@ is a Python operator for inner product; Java does not have one).
  • Added notation for creating Java arrays. Type[s1][s2][s3] for arrays of fixed sizes, Type[:][:][:] for arrays to be created later.
  • @FunctionalInterface allows you to create Java functors from Python objects with __call__.
  • Removed deprecated JIterator, JException factory usage, get_default_jvm_path and jpype.reflect.
  • By default, Java strings are not converted to Python strings.
  • Python has deprecated "__int__", so implicit casts between integer and float types will produce a TypeError.
  • Deprecated use of JException. To catch all exceptions, or to check that an object is a Java exception type, java.lang.Throwable follows.
  • Cascading Java exception causes are now reflected in Python stack frames.
  • Deprecated use of JString. To create a Java string, or check that an object is of type Java string, use java.lang.String.
  • Repr methods have been updated in Java classes.
  • java.util.List fulfills the contracts for collections.abc.Sequence and collections.abc.MutableSequence.
  • java.util.Collection fulfills the contract of for collections.abc.Collection.
  • Java classes are private and will throw a TypeError when extended from Python.
  • Handle Control-C neatly. Previous versions crash when Java processes a Control-C signal, as they will terminate Java during the call. JPype will now throw an InterruptedException when it returns from Java. Control-C won't kick out large Java routines as it currently does, since Java doesn't have a special facility for that.

A patch release of 1.0.1 was then formed, which added changes to work around problems with the release of Python 3.8.4. Python changed the logic regarding the use of "__setattr__" for "object" and "type", preventing it from being used to change derived classes. Also, error checking has been delegated from the "__setattr__" method, so the exception types in some sanity checks need to be updated accordingly.

Source: opennet.ru

Add a comment