Skip to content

Commit 2f734b3

Browse files
committed
swap arguments in polyglot.export_value
1 parent f404ee6 commit 2f734b3

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ language runtime. The main focus is on user-observable behavior of the engine.
77

88
* Add `java.add_to_classpath` API to dynamically extend the host class path
99
* Allow write access to main module bindings for embedder
10+
* Swap arguments for `polyglot.export_value` to use the more natural (name, value) order and deprecate the previous argument order.
1011

1112
## Version 20.0.0 beta 1
1213

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/JavaModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ Object type(PString name) {
116116
abstract static class AddToClassPathNode extends PythonBuiltinNode {
117117
@Specialization
118118
PNone add(VirtualFrame frame, Object[] args,
119-
@Cached CastToStringNode castToString) {
119+
@Cached CastToStringNode castToString) {
120120
Env env = getContext().getEnv();
121121
if (!env.isHostLookupAllowed()) {
122122
throw raise(PythonErrorType.NotImplementedError, "host access is not allowed");

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/PolyglotModuleBuiltins.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,15 @@ protected boolean isMimeType(String lang) {
231231
}
232232
}
233233

234-
@Builtin(name = "export_value", minNumOfPositionalArgs = 1, parameterNames = {"value", "name"})
234+
@Builtin(name = "export_value", minNumOfPositionalArgs = 1, parameterNames = {"name", "value"})
235235
@GenerateNodeFactory
236236
public abstract static class ExportSymbolNode extends PythonBuiltinNode {
237237
@Child private GetAttributeNode getNameAttributeNode;
238238
@Child private CastToStringNode castToStringNode;
239239

240-
@Specialization
240+
@Specialization(guards = "!isString(value)")
241241
@TruffleBoundary
242-
public Object exportSymbol(Object value, String name) {
242+
public Object exportSymbolKeyValue(String name, Object value) {
243243
Env env = getContext().getEnv();
244244
if (!env.isPolyglotAccessAllowed()) {
245245
throw raise(PythonErrorType.NotImplementedError, "polyglot access is not allowed");
@@ -248,6 +248,23 @@ public Object exportSymbol(Object value, String name) {
248248
return value;
249249
}
250250

251+
@Specialization(guards = "!isString(value)")
252+
@TruffleBoundary
253+
public Object exportSymbolValueKey(Object value, String name) {
254+
PythonLanguage.getLogger().warning("[deprecation] polyglot.export_value(value, name) is deprecated " +
255+
"and will be removed. Please swap the arguments.");
256+
return exportSymbolKeyValue(name, value);
257+
}
258+
259+
@Specialization(guards = "isString(arg1)")
260+
@TruffleBoundary
261+
public Object exportSymbolAmbiguous(Object arg1, String arg2) {
262+
PythonLanguage.getLogger().warning("[deprecation] polyglot.export_value(str, str) is ambiguous. In the future, this will " +
263+
"default to using the first argument as the name and the second as value, but now it " +
264+
"uses the first argument as value and the second as the name.");
265+
return exportSymbolValueKey(arg1, arg2);
266+
}
267+
251268
@Specialization
252269
@TruffleBoundary
253270
public Object exportSymbol(PFunction fun, @SuppressWarnings("unused") PNone name) {

0 commit comments

Comments
 (0)