Skip to content

Commit eb05517

Browse files
committed
Fix warnings.
1 parent 2fe1970 commit eb05517

File tree

8 files changed

+145
-59
lines changed

8 files changed

+145
-59
lines changed

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public interface Backend
124124
// Get the signature of a Python callable.
125125
PyObject getSignature(PyCallable obj);
126126

127-
PyObject getattrDefault(PyObject obj, Object key);
127+
PyObject getattrDefault(PyObject obj, Object key, PyObject defaultValue);
128128

129129
// Get an attribute from a Python object by key.
130130
PyObject getattrObject(PyObject obj, Object key);
@@ -289,17 +289,16 @@ public interface Backend
289289
// Create an empty Python `set`.
290290
PySet set();
291291

292-
// Set an attribute on a Python object.
293-
void setattrString(Object obj, CharSequence attrName, Object value);
294292

295293
// Set an attribute on a Python object and return the updated object.
296294
PyObject setattrReturn(PyObject obj, CharSequence attrName, PyObject value);
297-
298-
// Set an item in a Python mapping object by string key.
299-
void setitemFromString(Object obj, CharSequence key, Object value);
295+
// Set an attribute on a Python object.
296+
void setattrString(Object obj, CharSequence attrName, Object value);
300297

301298
// Set an item in a Python mapping object by object key.
302299
PyObject setitemFromObject(Object obj, Object key, Object value);
300+
// Set an item in a Python mapping object by string key.
301+
void setitemFromString(Object obj, CharSequence key, Object value);
303302

304303
// Create a Python `slice` object.
305304
PySlice slice(Integer start, Integer stop, Integer step);
@@ -319,9 +318,7 @@ public interface Backend
319318
// Get the `__dict__` attribute of a Python object.
320319
PyDict vars(Object obj);
321320

322-
public PyZip zipFromArray(PyObject[] objects);
323-
324-
public PyZip zipFromArray(Object[] objects);
321+
PyZip zipFromArray(Object[] objects);
325322

326323
// Create a Python `zip` object from multiple objects.
327324
<T> PyZip zipFromIterable(T... objects);

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

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -184,18 +184,6 @@ public static void exec(CharSequence statement, PyDict globals, PyMapping locals
184184
backend().eval(statement, globals, locals);
185185
}
186186

187-
/**
188-
* Retrieves the value of an attribute from a Python object.
189-
*
190-
* @param obj the Python object to inspect.
191-
* @param key the name of the attribute to retrieve.
192-
* @return the value of the attribute as a {@link PyObject}.
193-
*/
194-
public static PyObject getattr(PyObject obj, CharSequence key)
195-
{
196-
return backend().getattrString(obj, key);
197-
}
198-
199187
/**
200188
* Retrieves the value of an attribute from a Python object.
201189
*
@@ -210,7 +198,7 @@ public static PyObject getattr(PyObject obj, Object key)
210198

211199
public static PyObject getattrDefault(PyObject obj, Object key, PyObject defaultValue)
212200
{
213-
return backend().getattrDefault(obj, key);
201+
return backend().getattrDefault(obj, key, defaultValue);
214202
}
215203

216204
/**
@@ -472,13 +460,13 @@ public static <T> PyTuple tuple()
472460
/**
473461
* Creates a Python tuple from a variable-length array of arguments.
474462
*
475-
* @param args the objects to include in the tuple.
463+
* @param items the objects to include in the tuple.
476464
* @param <T> the type of the objects.
477465
* @return a new {@link PyTuple} instance containing the objects.
478466
*/
479-
public static <T> PyTuple tuple(T... args)
467+
public static <T> PyTuple tuple(T... items)
480468
{
481-
return backend().newTupleFromArray(args);
469+
return backend().newTupleFromArray(items);
482470
}
483471

484472
/**

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

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,21 +94,49 @@ static PyByteArray fromHex(CharSequence str)
9494
}
9595

9696
/**
97-
* Decodes the contents of the bytearray using the specified encoding.
98-
* Optionally, specific bytes can be deleted during decoding.
97+
* Decodes a bytearray object into a Python string.
9998
*
100-
* @param encoding the encoding to use for decoding (e.g., "utf-8").
101-
* @param delete the bytes to delete during decoding, or {@code null} for no
102-
* deletion.
103-
* @return a {@link PyObject} representing the decoded string.
99+
* <p>
100+
* Values for encoding include:</p>
101+
* <ul>
102+
* <li>"utf-8" (default)</li>
103+
* <li>"ascii"</li>
104+
* <li>"latin-1"</li>
105+
* <li>"utf-16"</li>
106+
* <li>"utf-32"</li>
107+
* <li>"cp1252" (Windows encoding)</li>
108+
* </ul>
109+
*
110+
* <p>
111+
* Values for errors include:</p>
112+
* <ul>
113+
* <li>"strict" (default): Raises a UnicodeDecodeError for invalid data.</li>
114+
* <li>"ignore": Ignores invalid characters.</li>
115+
* <li>"replace": Replaces invalid characters with a replacement character
116+
* (e.g., ? or �).</li>
117+
* <li>"backslashreplace": Replaces invalid characters with Python-style
118+
* escape sequences (e.g., \xNN).</li>
119+
* <li>"namereplace": Replaces invalid characters with \N{name} escape
120+
* sequences.</li>
121+
* <li>"surrogateescape": Uses special surrogate code points for invalid
122+
* bytes.</li>
123+
* </ul>
124+
*
125+
* @param encoding The character encoding to use for decoding the bytes
126+
* object. Common values include "utf-8", "ascii", "latin-1", etc or null if
127+
* not applicable.
128+
* @param errors An optional argument to specify how to handle errors during
129+
* decoding. Can be "strict", "ignore", "replace", etc., or null if not
130+
* applicable.
131+
* @return A new string resulting from decoding the bytearray object.
104132
*/
105-
PyObject decode(PyObject encoding, PyObject delete);
133+
PyObject decode(PyObject encoding, PyObject errors);
106134

107135
default int size()
108136
{
109137
return Interpreter.getBackend().len(this);
110138
}
111-
139+
112140
/**
113141
* Translates the contents of the bytearray using a translation table. The
114142
* translation table maps byte values to their replacements.

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

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,50 @@ static PyType type()
9696
return (PyType) PyBuiltIn.eval("bytes", null, null);
9797
}
9898

99-
PyObject decode(PyObject string, PyObject encoding);
99+
/**
100+
* Decodes a bytes object into a Python string.
101+
*
102+
* <p>
103+
* Values for encoding include:</p>
104+
* <ul>
105+
* <li>"utf-8" (default)</li>
106+
* <li>"ascii"</li>
107+
* <li>"latin-1"</li>
108+
* <li>"utf-16"</li>
109+
* <li>"utf-32"</li>
110+
* <li>"cp1252" (Windows encoding)</li>
111+
* </ul>
112+
*
113+
* <p>
114+
* Values for errors include:</p>
115+
* <ul>
116+
* <li>"strict" (default): Raises a UnicodeDecodeError for invalid data.</li>
117+
* <li>"ignore": Ignores invalid characters.</li>
118+
* <li>"replace": Replaces invalid characters with a replacement character
119+
* (e.g., ? or �).</li>
120+
* <li>"backslashreplace": Replaces invalid characters with Python-style
121+
* escape sequences (e.g., \xNN).</li>
122+
* <li>"namereplace": Replaces invalid characters with \N{name} escape
123+
* sequences.</li>
124+
* <li>"surrogateescape": Uses special surrogate code points for invalid
125+
* bytes.</li>
126+
* </ul>
127+
*
128+
* @param encoding The character encoding to use for decoding the bytes
129+
* object. Common values include "utf-8", "ascii", "latin-1", etc or null if
130+
* not applicable.
131+
* @param errors An optional argument to specify how to handle errors during
132+
* decoding. Can be "strict", "ignore", "replace", etc., or null if not
133+
* applicable.
134+
* @return a new string resulting from decoding the bytes object.
135+
*/
136+
PyString decode(CharSequence encoding, CharSequence errors);
100137

138+
/**
139+
* Gets the length of a bytearray object in bytes.
140+
*
141+
* @return the length of the bytearray object, measured in bytes.
142+
*/
101143
default int size()
102144
{
103145
return Interpreter.getBackend().len(this);

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

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Collection;
2222
import java.util.Iterator;
2323
import java.util.List;
24+
import java.util.ListIterator;
2425
import org.jpype.bridge.Interpreter;
2526

2627
/**
@@ -70,18 +71,6 @@
7071
public interface PyList extends PyObject, List<PyObject>, PyIterable
7172
{
7273

73-
/**
74-
* Creates a new Python `list` object from the given a list of objects.
75-
*
76-
* @param items is an array whose elements will populate the new Python list.
77-
* @return a new {@link PyList} instance containing the elements.
78-
*/
79-
80-
public static PyList of(Object... items)
81-
{
82-
return Interpreter.getBackend().newListFromArray(items);
83-
}
84-
8574
/**
8675
* Creates a new Python `list` object from the given {@link Iterable}.
8776
*
@@ -97,6 +86,18 @@ public static PyList fromItems(Iterable c)
9786
return Interpreter.getBackend().newListFromIterable(c);
9887
}
9988

89+
/**
90+
* Creates a new Python `list` object from the given a list of objects.
91+
*
92+
* @param items is an array whose elements will populate the new Python list.
93+
* @return a new {@link PyList} instance containing the elements.
94+
*/
95+
96+
public static PyList of(Object... items)
97+
{
98+
return Interpreter.getBackend().newListFromArray(items);
99+
}
100+
100101
/**
101102
* Retrieves the Python type object for `list`. This is equivalent to
102103
* evaluating `type(list)` in Python.
@@ -252,6 +253,35 @@ default Iterator<PyObject> iterator()
252253
return new PyIterator(this.iter());
253254
}
254255

256+
/**
257+
* Returns a list iterator over the elements in the tuple.
258+
*
259+
* @return a list iterator starting at the beginning of the tuple
260+
*/
261+
@Override
262+
default ListIterator<PyObject> listIterator()
263+
{
264+
return new PyListIterator(this, 0);
265+
}
266+
267+
/**
268+
* Returns a list iterator over the elements in the tuple, starting at the
269+
* specified index.
270+
*
271+
* @param index the starting index for the iterator
272+
* @return a list iterator starting at the specified index
273+
* @throws IndexOutOfBoundsException if the index is out of range
274+
*/
275+
@Override
276+
default ListIterator<PyObject> listIterator(int index)
277+
{
278+
if (index < 0 || index > size())
279+
{
280+
throw new IndexOutOfBoundsException();
281+
}
282+
return new PyListIterator(this, index);
283+
}
284+
255285
/**
256286
* Removes the first occurrence of the specified object from the list.
257287
*
@@ -402,4 +432,5 @@ default <T> T[] toArray(T[] a)
402432
{
403433
return (T[]) new ArrayList<>(this).toArray(a);
404434
}
435+
405436
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.jpype.bridge.Interpreter;
2424
import python.lang.PyDict;
2525
import python.lang.PyDictItems;
26+
import python.lang.PyDictKeySet;
2627
import python.lang.PyList;
2728
import python.lang.PyObject;
2829

@@ -65,8 +66,6 @@
6566
* attributes.clear();
6667
* </pre>
6768
*
68-
* @param <CharSequence> The type of keys used for attribute names.
69-
* @param <PyObject> The type of values stored in the attributes.
7069
*/
7170
public class PyAttributes implements Map<CharSequence, PyObject>
7271
{
@@ -170,7 +169,7 @@ public PyList dir()
170169

171170
@Override
172171
public Set<Entry<CharSequence, PyObject>> entrySet()
173-
{
172+
{
174173
return new PyDictItems(this.asDict());
175174
}
176175

@@ -238,7 +237,7 @@ public boolean isEmpty()
238237
@Override
239238
public Set<CharSequence> keySet()
240239
{
241-
throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody
240+
return new PyDictKeySet(asDict());
242241
}
243242

244243
/**
@@ -261,7 +260,7 @@ public PyObject put(CharSequence key, PyObject value)
261260
/**
262261
* Unsupported operation for adding multiple attributes.
263262
*
264-
* @param collection The map of attributes to add.
263+
* @param map is the map of attributes to add.
265264
* @throws UnsupportedOperationException Always thrown.
266265
*/
267266
@Override

native/jpype_module/src/main/java/python/protocol/PyCallable.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,24 +196,24 @@ public CallBuilder(PyCallable callable)
196196
/**
197197
* Adds a single positional argument to the call sequence.
198198
*
199-
* @param arg the argument to add
200-
* @return this {@link CallBuilder} instance for chaining
199+
* @param value is the argument to add.
200+
* @return this {@link CallBuilder} instance for chaining.
201201
*/
202-
public CallBuilder arg(Object arg)
202+
public CallBuilder arg(Object value)
203203
{
204-
jargs.add(arg);
204+
jargs.add(value);
205205
return this;
206206
}
207207

208208
/**
209209
* Adds multiple positional arguments to the call sequence.
210210
*
211-
* @param args the arguments to add
212-
* @return this {@link CallBuilder} instance for chaining
211+
* @param values is the arguments to add.
212+
* @return this {@link CallBuilder} instance for chaining.
213213
*/
214-
public CallBuilder arg(Object... args)
214+
public CallBuilder arg(Object... values)
215215
{
216-
jargs.addAll(Arrays.asList(args));
216+
jargs.addAll(Arrays.asList(values));
217217
return this;
218218
}
219219

native/jpype_module/src/test/java/python/lang/PyTupleNGTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public void testType()
7575
}
7676

7777
@Test
78+
@SuppressWarnings("element-type-mismatch")
7879
public void testContains()
7980
{
8081
PyTuple tuple = PyTuple.of("a", "b");

0 commit comments

Comments
 (0)