Skip to content

Commit 112c4bd

Browse files
committed
Fix docstring errors and update README
1 parent ec6a1ab commit 112c4bd

File tree

4 files changed

+77
-53
lines changed

4 files changed

+77
-53
lines changed

README.md

+42-25
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ FUNCTIONS
180180

181181
This function is a shortcut for Java's System.gc().
182182

183-
:raise RuntimeError: if the JVM has not yet been started.
183+
:raise RuntimeError: If the JVM has not started yet.
184184

185185
get_version(java_class_or_python_package) -> str
186186
Return the version of a Java class or Python package.
@@ -213,13 +213,13 @@ FUNCTIONS
213213
those actions via the jpype.setupGuiEnvironment wrapper function;
214214
see the Troubleshooting section of the scyjava README for details.
215215

216-
is_jarray(data) -> bool
216+
is_jarray(data: Any) -> bool
217217
Return whether the given data object is a Java array.
218218

219219
is_jvm_headless() -> bool
220220
Return true iff Java is running in headless mode.
221221

222-
:raises RuntimeError: If the JVM has not started yet.
222+
:raise RuntimeError: If the JVM has not started yet.
223223

224224
is_memoryarraylike(arr: Any) -> bool
225225
Return True iff the object is memoryarraylike:
@@ -265,7 +265,7 @@ FUNCTIONS
265265
:param lengths: List of lengths for the array. For example:
266266
`jarray('z', [3, 7])` is the equivalent of `new boolean[3][7]` in Java.
267267
You can pass a single integer to make a 1-dimensional array of that length.
268-
:returns: The newly allocated array
268+
:return: The newly allocated array
269269

270270
jclass(data)
271271
Obtain a Java class object.
@@ -285,22 +285,23 @@ FUNCTIONS
285285
i.e. the Java class for the Class class. :-)
286286

287287
:param data: The object from which to glean the class.
288-
:returns: A java.lang.Class object, suitable for use with reflection.
289-
:raises TypeError: if the argument is not one of the aforementioned types.
288+
:return: A java.lang.Class object, suitable for use with reflection.
289+
:raise TypeError: if the argument is not one of the aforementioned types.
290290

291291
jimport(class_name: str)
292292
Import a class from Java to Python.
293293

294294
:param class_name: Name of the class to import.
295-
:returns: A pointer to the class, which can be used to
296-
e.g. instantiate objects of that class.
295+
:return:
296+
A pointer to the class, which can be used to
297+
e.g. instantiate objects of that class.
297298

298299
jinstance(obj, jtype) -> bool
299300
Test if the given object is an instance of a particular Java type.
300301

301302
:param obj: The object to check.
302303
:param jtype: The Java type, as either a jimported class or as a string.
303-
:returns: True iff the object is an instance of that Java type.
304+
:return: True iff the object is an instance of that Java type.
304305

305306
jstacktrace(exc) -> str
306307
Extract the Java-side stack trace from a Java exception.
@@ -315,7 +316,7 @@ FUNCTIONS
315316
print(jstacktrace(exc))
316317

317318
:param exc: The Java Throwable from which to extract the stack trace.
318-
:returns: A multi-line string containing the stack trace, or empty string
319+
:return: A multi-line string containing the stack trace, or empty string
319320
if no stack trace could be extracted.
320321

321322
jvm_started() -> bool
@@ -379,8 +380,18 @@ FUNCTIONS
379380
:return: The used memory in bytes.
380381
:raise RuntimeError: if the JVM has not yet been started.
381382

383+
numeric_bounds(the_type: type) -> Union[Tuple[int, int], Tuple[float, float], Tuple[NoneType, NoneType]]
384+
Get the minimum and maximum values for the given numeric type.
385+
For example, a Java long returns (int(Long.MIN_VALUE), int(Long.MAX_VALUE)),
386+
whereas a Java double returns (float(-Double.MAX_VALUE), float(Double.MAX_VALUE)).
387+
388+
:param the_type: The type whose minimum and maximum values are needed.
389+
:return:
390+
The minimum and maximum values as a two-element tuple of int or float,
391+
or a two-element tuple of None if no known bounds.
392+
382393
shutdown_jvm() -> None
383-
Shutdown the JVM.
394+
Shut down the JVM.
384395

385396
This function makes a best effort to clean up Java resources first.
386397
In particular, shutdown hooks registered with scyjava.when_jvm_stops
@@ -398,7 +409,7 @@ FUNCTIONS
398409
Note that if the JVM is not already running, then this function does
399410
nothing! In particular, shutdown hooks are skipped in this situation.
400411

401-
:raises RuntimeError: if this method is called while in Jep mode.
412+
:raise RuntimeError: if this method is called while in Jep mode.
402413

403414
start_jvm(options=None) -> None
404415
Explicitly connect to the Java virtual machine (JVM). Only one JVM can
@@ -407,8 +418,9 @@ FUNCTIONS
407418
time a scyjava function needing a JVM is invoked, one is started on the
408419
fly with the configuration specified via the scijava.config mechanism.
409420

410-
:param options: List of options to pass to the JVM. For example:
411-
['-Dfoo=bar', '-XX:+UnlockExperimentalVMOptions']
421+
:param options:
422+
List of options to pass to the JVM.
423+
For example: ['-Dfoo=bar', '-XX:+UnlockExperimentalVMOptions']
412424

413425
to_java(obj: Any, **hints: Dict) -> Any
414426
Recursively convert a Python object to a Java object.
@@ -451,11 +463,13 @@ FUNCTIONS
451463
* float values in Double range but outside float range convert to Double
452464
* float values outside double range convert to BigDecimal
453465

454-
:param obj: The Python object to convert.
455-
:param hints: An optional dictionary of hints, to help scyjava
456-
make decisions about how to do the conversion.
457-
:returns: A corresponding Java object with the same contents.
458-
:raises TypeError: if the argument is not one of the aforementioned types.
466+
:param obj:
467+
The Python object to convert.
468+
:param hints:
469+
An optional dictionary of hints, to help scyjava
470+
make decisions about how to do the conversion.
471+
:return: A corresponding Java object with the same contents.
472+
:raise TypeError: if the argument is not one of the aforementioned types.
459473

460474
to_python(data: Any, gentle: bool = False) -> Any
461475
Recursively convert a Java object to a Python object.
@@ -472,12 +486,15 @@ FUNCTIONS
472486
* Iterable -> collections.abc.Iterable
473487
* Iterator -> collections.abc.Iterator
474488

475-
:param data: The Java object to convert.
476-
:param gentle: If set, and the type cannot be converted, leaves
477-
the data alone rather than raising a TypeError.
478-
:returns: A corresponding Python object with the same contents.
479-
:raises TypeError: if the argument is not one of the aforementioned types,
480-
and the gentle flag is not set.
489+
:param data:
490+
The Java object to convert.
491+
:param gentle:
492+
If set, and the type cannot be converted, leaves
493+
the data alone rather than raising a TypeError.
494+
:return: A corresponding Python object with the same contents.
495+
:raise TypeError:
496+
if the argument is not one of the aforementioned types,
497+
and the gentle flag is not set.
481498

482499
when_jvm_starts(f) -> None
483500
Registers a function to be called when the JVM starts (or immediately).

src/scyjava/_convert.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,13 @@ def to_java(obj: Any, **hints: Dict) -> Any:
184184
* float values in Double range but outside float range convert to Double
185185
* float values outside double range convert to BigDecimal
186186
187-
:param obj: The Python object to convert.
188-
:param hints: An optional dictionary of hints, to help scyjava
189-
make decisions about how to do the conversion.
190-
:returns: A corresponding Java object with the same contents.
191-
:raises TypeError: if the argument is not one of the aforementioned types.
187+
:param obj:
188+
The Python object to convert.
189+
:param hints:
190+
An optional dictionary of hints, to help scyjava
191+
make decisions about how to do the conversion.
192+
:return: A corresponding Java object with the same contents.
193+
:raise TypeError: if the argument is not one of the aforementioned types.
192194
"""
193195
start_jvm()
194196
return _convert(obj, java_converters, **hints)
@@ -197,7 +199,7 @@ def to_java(obj: Any, **hints: Dict) -> Any:
197199
def _stock_java_converters() -> List[Converter]:
198200
"""
199201
Construct the Python-to-Java converters supported out of the box.
200-
:returns: A list of Converters
202+
:return: A list of Converters
201203
"""
202204
start_jvm()
203205
return [
@@ -532,12 +534,15 @@ def to_python(data: Any, gentle: bool = False) -> Any:
532534
* Iterable -> collections.abc.Iterable
533535
* Iterator -> collections.abc.Iterator
534536
535-
:param data: The Java object to convert.
536-
:param gentle: If set, and the type cannot be converted, leaves
537-
the data alone rather than raising a TypeError.
538-
:returns: A corresponding Python object with the same contents.
539-
:raises TypeError: if the argument is not one of the aforementioned types,
540-
and the gentle flag is not set.
537+
:param data:
538+
The Java object to convert.
539+
:param gentle:
540+
If set, and the type cannot be converted, leaves
541+
the data alone rather than raising a TypeError.
542+
:return: A corresponding Python object with the same contents.
543+
:raise TypeError:
544+
if the argument is not one of the aforementioned types,
545+
and the gentle flag is not set.
541546
"""
542547
start_jvm()
543548
try:
@@ -551,7 +556,7 @@ def to_python(data: Any, gentle: bool = False) -> Any:
551556
def _stock_py_converters() -> List:
552557
"""
553558
Construct the Java-to-Python converters supported out of the box.
554-
:returns: A list of Converters
559+
:return: A list of Converters
555560
"""
556561
start_jvm()
557562

src/scyjava/_jvm.py

+10-8
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ def start_jvm(options=None) -> None:
113113
time a scyjava function needing a JVM is invoked, one is started on the
114114
fly with the configuration specified via the scijava.config mechanism.
115115
116-
:param options: List of options to pass to the JVM. For example:
117-
['-Dfoo=bar', '-XX:+UnlockExperimentalVMOptions']
116+
:param options:
117+
List of options to pass to the JVM.
118+
For example: ['-Dfoo=bar', '-XX:+UnlockExperimentalVMOptions']
118119
"""
119120
# if JVM is already running -- break
120121
if jvm_started():
@@ -191,7 +192,7 @@ def start_jvm(options=None) -> None:
191192

192193

193194
def shutdown_jvm() -> None:
194-
"""Shutdown the JVM.
195+
"""Shut down the JVM.
195196
196197
This function makes a best effort to clean up Java resources first.
197198
In particular, shutdown hooks registered with scyjava.when_jvm_stops
@@ -209,7 +210,7 @@ def shutdown_jvm() -> None:
209210
Note that if the JVM is not already running, then this function does
210211
nothing! In particular, shutdown hooks are skipped in this situation.
211212
212-
:raises RuntimeError: if this method is called while in Jep mode.
213+
:raise RuntimeError: if this method is called while in Jep mode.
213214
"""
214215
if not jvm_started():
215216
return
@@ -255,7 +256,7 @@ def gc() -> None:
255256
256257
This function is a shortcut for Java's System.gc().
257258
258-
:raises RuntimeError: If the JVM has not started yet.
259+
:raise RuntimeError: If the JVM has not started yet.
259260
"""
260261
_assert_jvm_started()
261262
System = jimport("java.lang.System")
@@ -329,7 +330,7 @@ def is_jvm_headless() -> bool:
329330
"""
330331
Return true iff Java is running in headless mode.
331332
332-
:raises RuntimeError: If the JVM has not started yet.
333+
:raise RuntimeError: If the JVM has not started yet.
333334
"""
334335
if not jvm_started():
335336
raise RuntimeError("JVM has not started yet!")
@@ -394,8 +395,9 @@ def jimport(class_name: str):
394395
Import a class from Java to Python.
395396
396397
:param class_name: Name of the class to import.
397-
:returns: A pointer to the class, which can be used to
398-
e.g. instantiate objects of that class.
398+
:return:
399+
A pointer to the class, which can be used to
400+
e.g. instantiate objects of that class.
399401
"""
400402
if mode == Mode.JEP:
401403
module_path = class_name.rsplit(".", 1)

src/scyjava/_types.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def jclass(data):
7777
i.e. the Java class for the Class class. :-)
7878
7979
:param data: The object from which to glean the class.
80-
:returns: A java.lang.Class object, suitable for use with reflection.
81-
:raises TypeError: if the argument is not one of the aforementioned types.
80+
:return: A java.lang.Class object, suitable for use with reflection.
81+
:raise TypeError: if the argument is not one of the aforementioned types.
8282
"""
8383
if isinstance(data, str):
8484
# Name of a class -- case (A) above.
@@ -118,7 +118,7 @@ def jstacktrace(exc) -> str:
118118
print(jstacktrace(exc))
119119
120120
:param exc: The Java Throwable from which to extract the stack trace.
121-
:returns: A multi-line string containing the stack trace, or empty string
121+
:return: A multi-line string containing the stack trace, or empty string
122122
if no stack trace could be extracted.
123123
"""
124124
try:
@@ -187,7 +187,7 @@ def jinstance(obj, jtype) -> bool:
187187
188188
:param obj: The object to check.
189189
:param jtype: The Java type, as either a jimported class or as a string.
190-
:returns: True iff the object is an instance of that Java type.
190+
:return: True iff the object is an instance of that Java type.
191191
"""
192192
if isinstance(jtype, str):
193193
jtype = jimport(jtype)
@@ -217,7 +217,7 @@ def jarray(kind, lengths: Sequence):
217217
:param lengths: List of lengths for the array. For example:
218218
`jarray('z', [3, 7])` is the equivalent of `new boolean[3][7]` in Java.
219219
You can pass a single integer to make a 1-dimensional array of that length.
220-
:returns: The newly allocated array
220+
:return: The newly allocated array
221221
"""
222222
if isinstance(kind, str):
223223
kind = kind.lower()
@@ -286,7 +286,7 @@ def numeric_bounds(
286286
"""
287287
Get the minimum and maximum values for the given numeric type.
288288
For example, a Java long returns (int(Long.MIN_VALUE), int(Long.MAX_VALUE)),
289-
whereas a Java double returns (double(-Double.MAX_VALUE), double(Double.MAX_VALUE)).
289+
whereas a Java double returns (float(-Double.MAX_VALUE), float(Double.MAX_VALUE)).
290290
291291
:param the_type: The type whose minimum and maximum values are needed.
292292
:return:
@@ -326,7 +326,7 @@ def _is_jtype(the_type: type, class_name: str) -> bool:
326326
327327
:param the_type: The type object to check.
328328
:param class_name: The fully qualified Java class name in string form.
329-
:returns: True iff the type is exactly that Java type.
329+
:return: True iff the type is exactly that Java type.
330330
"""
331331
# NB: Stringify the type to support both bridge modes. Ex:
332332
# * JPype: <java class 'java.lang.Integer'>

0 commit comments

Comments
 (0)