Skip to content

Commit e5b067a

Browse files
committed
Update to Python-3.10+-style type hinting
1 parent 07150a1 commit e5b067a

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

src/appose/builder.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,24 @@
3131
TODO
3232
"""
3333

34-
import os
34+
from __future__ import annotations
35+
3536
from pathlib import Path
36-
from typing import Dict, List, Optional, Sequence, Union
3737

3838
from .environment import Environment
39-
from .paths import find_exe
40-
from .service import Service
39+
4140

4241
class Builder:
42+
"""
43+
TODO
44+
"""
45+
4346
def __init__(self):
44-
self.base_dir: Optional[Path] = None
47+
self.base_dir: Path | None = None
4548
self.system_path: bool = False
46-
self.conda_environment_yaml: Optional[Path] = None
47-
self.java_vendor: Optional[str] = None
48-
self.java_version: Optional[str] = None
49+
self.conda_environment_yaml: Path | None = None
50+
self.java_vendor: str | None = None
51+
self.java_version: str | None = None
4952

5053
def build(self):
5154
# TODO: Build the thing!

src/appose/environment.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@
3131
TODO
3232
"""
3333

34+
from __future__ import annotations
35+
3436
import os
3537
from pathlib import Path
36-
from typing import Dict, List, Optional, Sequence, Union
3738

3839
from .paths import find_exe
3940
from .service import Service
4041

4142

4243
class Environment:
43-
def __init__(self, base: Union[Path, str], use_system_path: bool = False):
44+
def __init__(self, base: Path | str, use_system_path: bool = False):
4445
self.base = Path(base).absolute()
4546
self.use_system_path = use_system_path
4647

@@ -71,8 +72,8 @@ def python(self) -> Service:
7172

7273
def groovy(
7374
self,
74-
class_path: Optional[Sequence[str]] = None,
75-
jvm_args: Optional[Sequence[str]] = None,
75+
class_path: list[str] | None = None,
76+
jvm_args: list[str] | None = None,
7677
) -> Service:
7778
"""
7879
Create a Groovy script service. Groovy (https://groovy-lang.org/)
@@ -101,11 +102,11 @@ def groovy(
101102
def java(
102103
self,
103104
main_class: str,
104-
class_path: Optional[Sequence[str]] = None,
105-
jvm_args: Optional[Sequence[str]] = None,
105+
class_path: list[str] | None = None,
106+
jvm_args: list[str] | None = None,
106107
) -> Service:
107108
# Collect classpath elements into a set, to avoid duplicate entries.
108-
cp: Dict[str] = {} # NB: Use dict instead of set to maintain insertion order.
109+
cp: dict[str] = {} # NB: Use dict instead of set to maintain insertion order.
109110

110111
# TODO: Ensure that the classpath includes Appose and its dependencies.
111112

@@ -134,7 +135,7 @@ def java(
134135
]
135136
return self.service(java_exes, *args)
136137

137-
def service(self, exes: Sequence[str], *args) -> Service:
138+
def service(self, exes: list[str], *args) -> Service:
138139
"""
139140
Create a service with the given command line arguments.
140141
@@ -156,7 +157,7 @@ def service(self, exes: Sequence[str], *args) -> Service:
156157
if not exes:
157158
raise ValueError("No executable given")
158159

159-
dirs: List[str] = (
160+
dirs: list[str] = (
160161
os.environ["PATH"].split(os.pathsep)
161162
if self.use_system_path
162163
else [self.base]
@@ -166,6 +167,6 @@ def service(self, exes: Sequence[str], *args) -> Service:
166167
if exe_file is None:
167168
raise ValueError(f"No executables found amongst candidates: {exes}")
168169

169-
all_args: List[str] = [str(exe_file)]
170+
all_args: list[str] = [str(exe_file)]
170171
all_args.extend(args)
171172
return Service(self.base, all_args)

src/appose/paths.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,17 @@
3131
Utility functions for working with file paths.
3232
"""
3333

34+
from __future__ import annotations
35+
3436
import os
3537
from pathlib import Path
36-
from typing import Optional, Sequence
3738

3839

3940
def can_execute(exe: Path) -> bool:
4041
return os.access(exe, os.X_OK)
4142

4243

43-
def find_exe(dirs: Sequence[str], exes: Sequence[str]) -> Optional[Path]:
44+
def find_exe(dirs: list[str], exes: list[str]) -> Path | None:
4445
for exe in exes:
4546
exe_file = Path(exe)
4647
if exe_file.is_absolute():

src/appose/types.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@
2727
# #L%
2828
###
2929

30+
"""
31+
TODO
32+
"""
33+
34+
from __future__ import annotations
35+
3036
import json
3137
import re
3238
from math import ceil, prod
3339
from multiprocessing import resource_tracker, shared_memory
34-
from typing import Any, Dict, Sequence, Union
40+
from typing import Any
3541

36-
Args = Dict[str, Any]
42+
Args = dict[str, Any]
3743

3844

3945
class SharedMemory(shared_memory.SharedMemory):
@@ -150,7 +156,7 @@ class NDArray:
150156
a particular shape, and flattened into SharedMemory.
151157
"""
152158

153-
def __init__(self, dtype: str, shape: Sequence[int], shm: SharedMemory = None):
159+
def __init__(self, dtype: str, shape: list[int], shm: SharedMemory = None):
154160
"""
155161
Create an NDArray.
156162
:param dtype: The type of the data elements; e.g. int8, uint8, float32, float64.
@@ -216,7 +222,7 @@ def default(self, obj):
216222
return super().default(obj)
217223

218224

219-
def _appose_object_hook(obj: Dict):
225+
def _appose_object_hook(obj: dict):
220226
atype = obj.get("appose_type")
221227
if atype == "shm":
222228
# Attach to existing shared memory block.
@@ -227,7 +233,7 @@ def _appose_object_hook(obj: Dict):
227233
return obj
228234

229235

230-
def _bytes_per_element(dtype: str) -> Union[int, float]:
236+
def _bytes_per_element(dtype: str) -> int | float:
231237
try:
232238
bits = int(re.sub("[^0-9]", "", dtype))
233239
except ValueError:

0 commit comments

Comments
 (0)