You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: CHANGELOG.md
+7-2Lines changed: 7 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -7,12 +7,17 @@ language runtime. The main focus is on user-observable behavior of the engine.
7
7
* Updated developer metadata of Maven artifacts.
8
8
* Added gradle plugin for polyglot embedding of Python packages into Java.
9
9
* When calling a method on a foreign object in Python code, Python methods are now prioritized over foreign members.
10
+
* Added `polyglot.register_interop_type` and `@polyglot.interop_type` to define custom Python methods for a given foreign class/type. See [the documentation](https://github.com/oracle/graalpython/blob/master/docs/user/Interoperability.md#the-interoperability-extension-api) for more information.
11
+
* Foreign objects are now given a Python class corresponding to their interop traits.
12
+
** Foreign lists now inherit from Python `list`, foreign dictionaries from `dict`, foreign iterators from `iterator`, foreign exceptions from `BaseException` and foreign none/null from `NoneType`.
13
+
** This means all Python methods of these types are available on the corresponding foreign objects, which behave as close as possible as if they were Python objects.
14
+
** See [the documentation](https://github.com/oracle/graalpython/blob/master/docs/user/Interoperability.md#interacting-with-foreign-objects-from-python-scripts) for more information.
10
15
11
16
## Version 24.1.0
12
17
* GraalPy is now considered stable for pure Python workloads. While many workloads involving native extension modules work, we continue to consider them experimental. You can use the command-line option `--python.WarnExperimentalFeatures` to enable warnings for such modules at runtime. In Java embeddings the warnings are enabled by default and you can suppress them by setting the context option 'python.WarnExperimentalFeatures' to 'false'.
13
18
* Update to Python 3.11.7.
14
19
* We now provide intrinsified `_pickle` module also in the community version.
15
-
*`polyglot.eval` now raises more meaningful exceptions. Unavaliable languages raise `ValueError`. Exceptions from the polyglot language are raised directly as interop objects (typed as `polyglot.ForeignException`). The shortcut for executing python files without specifying language has been removed, use regular `eval` for executing Python code.
20
+
*`polyglot.eval` now raises more meaningful exceptions. Unavailable languages raise `ValueError`. Exceptions from the polyglot language are raised directly as interop objects (typed as `polyglot.ForeignException`). The shortcut for executing python files without specifying language has been removed, use regular `eval` for executing Python code.
16
21
* In Jython emulation mode we now magically fall back to calling Java getters or setters when using Python attribute access for non-visible properties. This can help migrating away from Jython if you relied on this behavior.
17
22
* The option `python.EmulateJython` to enable Jython emulation is now marked as stable, and can thus be relied upon in production.
18
23
* Fixed parsing of pyvenv.cfg according to PEP 405, which is required to use [uv](https://github.com/astral-sh/uv?tab=readme-ov-file#uv) generated venvs with GraalPy.
@@ -33,7 +38,7 @@ language runtime. The main focus is on user-observable behavior of the engine.
33
38
* Add option `python.InitialLocale` to change the default locale. If not set, then Java Locale#getDefault is used.
34
39
*`multiprocessing` module now uses the `spawn` method (creates new processes) by default. The formerly default method that uses threads and multiple Truffle contexts can be selected using `multiprocessing.set_start_method('graalpy')`.
35
40
*`polyglot` module: add API to redefine Truffle interop messages for external / user defined types. For more details see [The Truffle Interoperability Extension API](docs/user/Interoperability.md).
36
-
*Adding integration with jBang (https://www.jbang.dev/)
41
+
*Adding integration with jBang (https://www.jbang.dev/)
37
42
** running example via `jbang hello@oracle/graalpython` or `jbang hello@oracle/graalpython "print(1*4)"`
38
43
** creating new script via: `jbang init --template=graalpy@oracle/graalpython myscript.java`
39
44
** creating new script with local maven repo for testing: `jbang init --template=graalpy_local_repo@oracle/graalpython -Dpath_to_local_repo=/absolute/path/to/local/maven/repository myscript.java'
For plain Python users, the `java` module is only available when running on the JVM distribution.
31
-
</aside>
32
-
33
29
To import packages from the `java` namespace, you can also use the conventional Python import syntax:
34
30
```python
35
31
import java.util.ArrayList
@@ -46,7 +42,7 @@ In addition to the `type` built-in method, the `java` module exposes the followi
46
42
47
43
Built-in | Specification
48
44
--- | ---
49
-
`instanceof(obj,class)` | returns `True` if `obj` is an instance of `class` (`class` must be a foreign object class)
45
+
`instanceof(obj,class)` | returns `True` if `obj` is an instance of `class` (`class` must be a foreign object class)
50
46
`is_function(obj)` | returns `True` if `obj` is a Java host language function wrapped using interop
51
47
`is_object(obj)` | returns `True` if `obj` if the argument is Java host language object wrapped using interop
52
48
`is_symbol(obj)` | returns `True` if `obj` if the argument is a Java host symbol, representing the constructor and static members of a Java class, as obtained by `java.type`
See [Polyglot Programming](https://github.com/oracle/graal/blob/master/docs/reference-manual/polyglot-programming.md) and [Embed Languages](https://github.com/oracle/graal/blob/master/docs/reference-manual/embedding/embed-languages.md) for more information about interoperability with other programming languages.
65
61
62
+
## Interacting with foreign objects from Python scripts
63
+
64
+
Foreign objects are given a Python class corresponding to their interop traits:
This means all Python methods of these types are available on the corresponding foreign objects, which behave as close as possible as if they were Python objects:
73
+
74
+
```python
75
+
from java.util import ArrayList, HashMap
76
+
l = ArrayList()
77
+
l.append(1) # l: [1]
78
+
l.extend([2, 3]) # l: [1, 2, 3]
79
+
l.add(4) # l: [1, 2, 3, 4] # we can still call Java methods, this is calling ArrayList#add
80
+
l[1:3] # => [2, 3]
81
+
l.pop(1) # => 2; l: [1, 3, 4]
82
+
l.insert(1, 2) # l: [1, 2, 3, 4]
83
+
l == [1, 2, 3, 4] # True
84
+
85
+
h = HashMap()
86
+
h[1] =2# h: {1: 2}
87
+
h.setdefault(3, 4) # h: {1: 2, 3: 4}
88
+
h |= {3: 6} # {1: 2, 3: 6}
89
+
h == {1: 2, 3: 6} # True
90
+
```
91
+
92
+
Specifically:
93
+
* Foreign lists inherit from Python `list`
94
+
* Foreign dictionaries inherit from `dict`
95
+
* Foreign iterators inherit from `iterator`
96
+
* Foreign exceptions inherit from `BaseException`
97
+
* Foreign none/null inherit from `NoneType`
98
+
66
99
## Interacting with other dynamic languages from Python scripts
67
100
68
101
More general, non-JVM specific interactions with other languages from Python scripts are achieved via the _polyglot_ API.
Copy file name to clipboardExpand all lines: graalpython/com.oracle.graal.python.test.integration/src/com/oracle/graal/python/test/integration/interop/JavaInteropTest.java
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -584,7 +584,7 @@ public void javaStringsAndPythonStrings() throws IOException {
0 commit comments