Skip to content

Commit 71e1a3b

Browse files
gselzerclaude
andcommitted
Assign the parameters the completion header declares
The header declared each parameter by annotation only, e.g. "image: numpy.ndarray". Some servers (e.g. ty) take a name that is only annotated to be unbound, and complete none of its members; so each is now also assigned, e.g. "image: numpy.ndarray = ...". Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ee7c337 commit 71e1a3b

2 files changed

Lines changed: 12 additions & 9 deletions

File tree

‎src/main/java/org/scijava/plugins/scripting/appose/python/completion/ApposePythonDialect.java‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,14 +103,16 @@ public Header header(final Map<String, Variable> variables) {
103103
code.add("import numpy");
104104
hidden.add("numpy");
105105
}
106-
// Declare the types of each parameter for type reasoning
106+
// Declare the types of each parameter for type reasoning. NB: Assigned
107+
// (to ...), as well as annotated: some servers (e.g. ty) take a name that
108+
// is only annotated to be unbound, and complete none of its members.
107109
variables.forEach((name, v) -> {
108110
final String t = parameterType(v.type());
109111
// NB: Values Appose cannot pass are not declared.
110-
if (t != null) code.add(name + ": " + t);
112+
if (t != null) code.add(name + ": " + t + " = ...");
111113
});
112114
// Declare the type of task for type reasoning
113-
code.add("task: " + TASK_TYPE);
115+
code.add("task: " + TASK_TYPE + " = ...");
114116
// Combine into a Header
115117
return new Header(String.join("; ", code), hidden);
116118
}

‎src/test/java/org/scijava/plugins/scripting/appose/python/completion/ApposePythonDialectTest.java‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,24 +109,25 @@ public void testParameterType() {
109109
@Test
110110
public void testHeader() {
111111
// SciJava Script parameters should be declared in Python code with the
112-
// types Appose converts them to, e.g. "image: numpy.ndarray"; and
113-
// scripts can use Appose's task variable
112+
// types Appose converts them to, e.g. "image: numpy.ndarray" (assigned,
113+
// so that servers take them to be bound); and scripts can use Appose's
114+
// task variable
114115
final Map<String, Variable> parameters = new LinkedHashMap<>();
115116
parameters.put("image", Variable.ofType(Img.class));
116117
parameters.put("sigma", Variable.ofType(double.class));
117118
parameters.put("context", Variable.ofType(Context.class));
118119
Header header = dialect.header(parameters);
119120
assertEquals("import appose.python_worker; import numpy; " +
120-
"image: numpy.ndarray; sigma: float; " +
121-
"task: appose.python_worker.Task", header.code());
121+
"image: numpy.ndarray = ...; sigma: float = ...; " +
122+
"task: appose.python_worker.Task = ...", header.code());
122123
// The imports' names are the header's alone
123124
assertEquals(Arrays.asList("appose", "numpy"), Arrays.asList(header
124125
.hiddenNames().toArray()));
125126
// numpy is imported only when a parameter needs it
126127
header = dialect.header(Collections.singletonMap("sigma", Variable
127128
.ofType(double.class)));
128-
assertEquals("import appose.python_worker; sigma: float; " +
129-
"task: appose.python_worker.Task", header.code());
129+
assertEquals("import appose.python_worker; sigma: float = ...; " +
130+
"task: appose.python_worker.Task = ...", header.code());
130131
assertEquals(Collections.singleton("appose"), header.hiddenNames());
131132
}
132133

0 commit comments

Comments
 (0)