Skip to content

Commit

Permalink
Add type hints in more places
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrueden committed Nov 3, 2022
1 parent 02971ec commit 23a713f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/scyjava/_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
Utility functions for working with and reasoning about arrays.
"""

from typing import Any

def is_arraylike(arr):

def is_arraylike(arr: Any) -> bool:
"""
Return True iff the object is arraylike: possessing
.shape, .dtype, .__array__, and .ndim attributes.
Expand All @@ -19,7 +21,7 @@ def is_arraylike(arr):
)


def is_memoryarraylike(arr):
def is_memoryarraylike(arr: Any) -> bool:
"""
Return True iff the object is memoryarraylike:
an arraylike object whose .data type is memoryview.
Expand All @@ -34,7 +36,7 @@ def is_memoryarraylike(arr):
)


def is_xarraylike(xarr):
def is_xarraylike(xarr: Any) -> bool:
"""
Return True iff the object is xarraylike:
possessing .values, .dims, and .coords attributes,
Expand Down
4 changes: 2 additions & 2 deletions src/scyjava/_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _convertIterable(obj: collections.abc.Iterable):
java_converters: List[Converter] = []


def add_java_converter(converter: Converter):
def add_java_converter(converter: Converter) -> None:
"""
Add a converter to the list used by to_java.
:param converter: A Converter going from python to java
Expand Down Expand Up @@ -467,7 +467,7 @@ def __str__(self):
py_converters: List[Converter] = []


def add_py_converter(converter: Converter):
def add_py_converter(converter: Converter) -> None:
"""
Add a converter to the list used by to_python.
:param converter: A Converter from java to python
Expand Down
12 changes: 6 additions & 6 deletions src/scyjava/_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import sys
from functools import lru_cache
from pathlib import Path
from typing import Callable
from typing import Callable, Sequence

import jpype
import jpype.config
Expand Down Expand Up @@ -76,7 +76,7 @@ def inner(self):
# -- JVM functions --


def jvm_version():
def jvm_version() -> str:
"""
Gets the version of the JVM as a tuple,
with each dot-separated digit as one element.
Expand Down Expand Up @@ -147,7 +147,7 @@ def jvm_version():
return tuple(map(int, m.group(1).split(".")))


def start_jvm(options=None):
def start_jvm(options=None) -> None:
"""
Explicitly connect to the Java virtual machine (JVM). Only one JVM can
be active; does nothing if the JVM has already been started. Calling
Expand Down Expand Up @@ -231,7 +231,7 @@ def start_jvm(options=None):
callback()


def shutdown_jvm():
def shutdown_jvm() -> None:
"""Shutdown the JVM.
This function makes a best effort to clean up Java resources first.
Expand Down Expand Up @@ -355,7 +355,7 @@ def is_jarray(data) -> bool:


@lru_cache(maxsize=None)
def jimport(class_name):
def jimport(class_name: str):
"""
Import a class from Java to Python.
Expand Down Expand Up @@ -430,7 +430,7 @@ def jstacktrace(exc) -> str:
return ""


def jarray(kind, lengths):
def jarray(kind, lengths: Sequence):
"""
Create a new n-dimensional Java array.
Expand Down
4 changes: 2 additions & 2 deletions src/scyjava/_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
_logger = logging.getLogger(__name__)


def get_version(java_class_or_python_package):
def get_version(java_class_or_python_package) -> str:
"""
Return the version of a Java class or Python package.
Expand Down Expand Up @@ -48,7 +48,7 @@ def get_version(java_class_or_python_package):
raise RuntimeError("Cannot determine version! Is pkg_resources installed?")


def is_version_at_least(actual_version, minimum_version):
def is_version_at_least(actual_version: str, minimum_version: str) -> bool:
"""
Return a boolean on a version comparison.
Requires org.scijava:scijava-common on the classpath.
Expand Down

0 comments on commit 23a713f

Please sign in to comment.