Skip to content

Commit 532aa13

Browse files
committed
So much typing....
1 parent e46b736 commit 532aa13

31 files changed

+278
-213
lines changed

native/jpype_module/src/main/java/org/jpype/bridge/Backend.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.jpype.bridge;
1717

1818
import java.util.Collection;
19+
import java.util.List;
1920
import java.util.Map;
2021
import java.util.Set;
2122
import java.util.concurrent.Future;
@@ -39,8 +40,6 @@
3940
import python.lang.PyZip;
4041
import python.lang.PyBuffer;
4142
import python.lang.PyCallable;
42-
import python.lang.PyIndex;
43-
import python.lang.PyMapping;
4443
import python.lang.PyIter;
4544

4645
/**
@@ -91,12 +90,11 @@ public interface Backend
9190
boolean contains(Object obj, Object value);
9291

9392
// Delete an item from a Python sequence by index.
94-
boolean delByIndex(Object obj, int index);
93+
void delitemByIndex(Object obj, int index);
9594

96-
// Delete an item from a Python mapping object by key.
97-
PyObject delByObject(PyMapping obj, Object key);
95+
void delitemByObject(Object obj, Object index);
9896

99-
PyObject delattrReturn(PyObject obj, Object key);
97+
PyObject delattrReturn(Object obj, Object key);
10098

10199
// Delete an attribute from a Python object by name.
102100
void delattrString(Object obj, CharSequence attrName);
@@ -113,9 +111,6 @@ public interface Backend
113111
// Execute a Python statement with optional global and local variables.
114112
void exec(CharSequence source, PyDict globals, PyObject locals);
115113

116-
// Get the type of a Python callable as a string.
117-
String getCallableType(PyCallable obj);
118-
119114
// Get the `__dict__` attribute of a Python object.
120115
PyDict getDict(Object obj);
121116

@@ -209,7 +204,7 @@ public interface Backend
209204
// Create a Python `bytearray` from an iterable.
210205
PyByteArray newByteArrayFromIterable(Iterable<?> iter);
211206

212-
public PyByteArray newByteArrayFromIterator(Iterable<PyObject> iterable);
207+
PyByteArray newByteArrayFromIterator(Iterable<PyObject> iterable);
213208

214209
// Create a Python `bytearray` with a specified size.
215210
PyByteArray newByteArrayOfSize(int size);
@@ -265,7 +260,7 @@ public interface Backend
265260
PyTuple newTuple();
266261

267262
// Create a Python `tuple` from an array of objects.
268-
PyTuple newTupleFromArray(Object... elements);
263+
PyTuple newTupleFromArray(List<?> elements);
269264

270265
// Create a Python `tuple` from an iterable.
271266
PyTuple newTupleFromIterator(Iterable<?> iterable);
@@ -317,7 +312,7 @@ public interface Backend
317312
PyString str(Object obj);
318313

319314
// Create a Python `tee` iterator.
320-
PyIter teeIterator(PyIter iterator);
315+
<T> PyIter<T> teeIterator(PyIter<T> iterator);
321316

322317
// Get the type of a Python object.
323318
PyType type(Object obj);
@@ -331,5 +326,5 @@ public interface Backend
331326
PyZip zipFromArray(Object[] objects);
332327

333328
// Create a Python `zip` object from multiple objects.
334-
PyZip zipFromIterable(Object... objects);
329+
PyZip zipFromIterable(Iterable<?> objects);
335330
}

native/jpype_module/src/main/java/org/jpype/bridge/Context.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import python.lang.PyBuiltIn;
1919
import python.lang.PyDict;
2020
import python.lang.PyObject;
21-
import python.lang.PyMapping;
2221

2322
/**
2423
* Represents an scope of variables in the Python interpreter.

native/jpype_module/src/main/java/python/lang/PyAbstractSet.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717

1818
import java.util.Iterator;
1919
import java.util.Set;
20-
import org.jpype.bridge.Interpreter;
21-
import python.lang.PyBuiltIn;
22-
import python.lang.PyObject;
23-
import python.lang.PySet;
20+
import static python.lang.PyBuiltIn.backend;
2421

2522
/**
2623
* Represents a protocol for Python classes that act as sets.
@@ -55,7 +52,7 @@ public interface PyAbstractSet<T extends PyObject> extends PyCollection<T>, Set<
5552
@Override
5653
default boolean contains(Object obj)
5754
{
58-
return Interpreter.getBackend().contains(this, obj);
55+
return backend().contains(this, obj);
5956
}
6057

6158
/**
@@ -71,7 +68,7 @@ default boolean contains(Object obj)
7168
*/
7269
static <T> PySet of(Iterable<T> c)
7370
{
74-
return Interpreter.getBackend().newSetFromIterable(c);
71+
return backend().newSetFromIterable(c);
7572
}
7673

7774
/**

native/jpype_module/src/main/java/python/lang/PyAttributes.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,7 @@
1919
import java.util.Map;
2020
import java.util.Set;
2121
import org.jpype.bridge.Backend;
22-
import python.lang.PyBuiltIn;
23-
import org.jpype.bridge.Interpreter;
24-
import python.lang.PyDict;
25-
import python.lang.PyDictItems;
26-
import python.lang.PyDictKeySet;
27-
import python.lang.PyList;
28-
import python.lang.PyObject;
22+
import static python.lang.PyBuiltIn.backend;
2923

3024
/**
3125
* A {@link Map}-like implementation for accessing and manipulating Python
@@ -94,7 +88,7 @@ public class PyAttributes implements Map<PyObject, PyObject>
9488
public PyAttributes(PyObject obj)
9589
{
9690
this.obj = obj;
97-
this.backend = Interpreter.getBackend();
91+
this.backend = backend();
9892
}
9993

10094
/**

native/jpype_module/src/main/java/python/lang/PyAwaitable.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package python.lang;
1717

18-
import python.lang.PyObject;
19-
2018
/**
2119
* Protocol for objects that are awaitable.
2220
*/

native/jpype_module/src/main/java/python/lang/PyBuffer.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package python.lang;
1717

18-
import python.lang.PyObject;
19-
2018
/**
2119
* Protocol for objects that act as a buffer.
2220
*/

native/jpype_module/src/main/java/python/lang/PyBuiltIn.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package python.lang;
1717

18+
import java.util.Arrays;
1819
import org.jpype.bridge.Backend;
1920
import org.jpype.bridge.Interpreter;
2021

@@ -29,6 +30,10 @@ public class PyBuiltIn
2930

3031
static Backend instance;
3132

33+
protected PyBuiltIn()
34+
{
35+
}
36+
3237
/**
3338
* Creates a new Python float object.
3439
*
@@ -62,11 +67,6 @@ public class PyBuiltIn
6267
* be accessed.
6368
* </p>
6469
*
65-
* <p>
66-
* The method also caches the backend instance for future use, avoiding
67-
* redundant calls to {@link Interpreter#getBackend()}.
68-
* </p>
69-
*
7070
* @return The active {@link Backend} instance.
7171
* @throws IllegalStateException If the interpreter is not started.
7272
*/
@@ -216,9 +216,9 @@ public static boolean hasattr(PyObject obj, CharSequence key)
216216
* indices.
217217
* @return a new {@link PyTuple} instance containing the indices.
218218
*/
219-
public static PyTuple indices(PyIndex[] indices)
219+
public static PyTuple indices(PyIndex... indices)
220220
{
221-
return backend().newTupleFromArray(indices);
221+
return backend().newTupleFromArray(Arrays.asList(indices));
222222
}
223223

224224
/**
@@ -464,7 +464,7 @@ public static <T> PyTuple tuple()
464464
*/
465465
public static PyTuple tuple(Object... items)
466466
{
467-
return backend().newTupleFromArray(items);
467+
return backend().newTupleFromArray(Arrays.asList(items));
468468
}
469469

470470
/**
@@ -506,6 +506,6 @@ public static PyDict vars(Object obj)
506506
*/
507507
public static PyZip zip(Iterable... objects)
508508
{
509-
return backend().zipFromIterable(objects);
509+
return backend().zipFromIterable(Arrays.asList(objects));
510510
}
511511
}

native/jpype_module/src/main/java/python/lang/PyByteArray.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package python.lang;
1717

1818
import org.jpype.bridge.Interpreter;
19+
import static python.lang.PyBuiltIn.backend;
1920

2021
/**
2122
* Java front-end interface for the concrete Python `bytearray` type.
@@ -37,7 +38,7 @@ public interface PyByteArray extends PyObject, PyBuffer, PySequence<PyInt>
3738
*/
3839
static PyByteArray create(int length)
3940
{
40-
return Interpreter.getBackend().newByteArrayOfSize(length);
41+
return backend().newByteArrayOfSize(length);
4142
}
4243

4344
/**
@@ -50,7 +51,7 @@ static PyByteArray create(int length)
5051
*/
5152
static PyByteArray fromHex(CharSequence str)
5253
{
53-
return Interpreter.getBackend().bytearrayFromHex(str);
54+
return backend().bytearrayFromHex(str);
5455
}
5556

5657
/**
@@ -64,7 +65,7 @@ static PyByteArray fromHex(CharSequence str)
6465
*/
6566
static PyByteArray of(Iterable<PyObject> iter)
6667
{
67-
return Interpreter.getBackend().newByteArrayFromIterable(iter);
68+
return backend().newByteArrayFromIterable(iter);
6869
}
6970

7071
/**
@@ -78,7 +79,7 @@ static PyByteArray of(Iterable<PyObject> iter)
7879
*/
7980
static PyByteArray of(PyBuffer bytes)
8081
{
81-
return Interpreter.getBackend().newByteArrayFromBuffer(bytes);
82+
return backend().newByteArrayFromBuffer(bytes);
8283
}
8384

8485
/**
@@ -157,7 +158,7 @@ default void set(PyIndex index, PyObject values)
157158
@Override
158159
default int size()
159160
{
160-
return Interpreter.getBackend().len(this);
161+
return backend().len(this);
161162
}
162163

163164
/**

native/jpype_module/src/main/java/python/lang/PyBytes.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
package python.lang;
1717

18-
import org.jpype.bridge.Interpreter;
18+
import static python.lang.PyBuiltIn.backend;
1919

2020
/**
2121
* Java front-end interface for the concrete Python `bytes` type.
@@ -35,7 +35,7 @@ public interface PyBytes extends PyObject, PyBuffer, PySequence<PyInt>
3535
*/
3636
static PyBytes create(int length)
3737
{
38-
return Interpreter.getBackend().newBytesOfSize(length);
38+
return backend().newBytesOfSize(length);
3939
}
4040

4141
/**
@@ -50,7 +50,7 @@ static PyBytes create(int length)
5050
*/
5151
static PyBytes fromHex(CharSequence str)
5252
{
53-
return Interpreter.getBackend().bytesFromHex(str);
53+
return backend().bytesFromHex(str);
5454
}
5555

5656
/**
@@ -65,7 +65,7 @@ static PyBytes fromHex(CharSequence str)
6565
*/
6666
static PyByteArray of(Iterable<PyObject> iterable)
6767
{
68-
return Interpreter.getBackend().newByteArrayFromIterator(iterable);
68+
return backend().newByteArrayFromIterator(iterable);
6969
}
7070

7171
/**
@@ -80,7 +80,7 @@ static PyByteArray of(Iterable<PyObject> iterable)
8080
*/
8181
static PyByteArray of(PyBuffer buffer)
8282
{
83-
return Interpreter.getBackend().newByteArrayFromBuffer(buffer);
83+
return backend().newByteArrayFromBuffer(buffer);
8484
}
8585

8686
/**
@@ -148,7 +148,7 @@ default PyInt set(int index, PyInt value)
148148
@Override
149149
default int size()
150150
{
151-
return Interpreter.getBackend().len(this);
151+
return backend().len(this);
152152
}
153153

154154
/**

0 commit comments

Comments
 (0)