Skip to content

Commit 625f310

Browse files
committed
Improve type hinting
* Address some typing errors noticed by mypy * Fix "Incomplete" API type hinting to satisfy stubgen
1 parent 2c3127a commit 625f310

17 files changed

Lines changed: 51 additions & 39 deletions

File tree

src/appose/builder/__init__.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ def __init__(
7777
verb = "interrupted" if isinstance(cause, KeyboardInterrupt) else "failed"
7878
message = f"{noun} {verb}"
7979
super().__init__(message)
80-
self.builder = builder
81-
self.__cause__ = cause
80+
self.builder: Builder | None = builder
81+
self.__cause__: Exception | None = cause
8282

8383

8484
class Builder(Protocol):
@@ -584,13 +584,13 @@ def __init__(
584584
bin_path_list: list[str],
585585
launch_arg_list: list[str],
586586
env_var_dict: dict[str, str],
587-
parent_builder: BaseBuilder,
587+
parent_builder: Builder,
588588
):
589589
super().__init__(base_path)
590-
self._bin_paths = bin_path_list
591-
self._launch_args = launch_arg_list
592-
self._env_vars = env_var_dict
593-
self._builder = parent_builder
590+
self._bin_paths: list[str] = bin_path_list
591+
self._launch_args: list[str] = launch_arg_list
592+
self._env_vars: dict[str, str] = env_var_dict
593+
self._builder: Builder = parent_builder
594594

595595
def bin_paths(self) -> list[str]:
596596
return self._bin_paths

src/appose/builder/mamba.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ class MambaBuilder(BaseBuilder):
4949
def __init__(self):
5050
super().__init__()
5151

52+
# Note: Already assigned in BaseBuilder, but stubgen wants these here, too.
53+
self.source_content: str | None = None
54+
self.scheme: str | None = None
55+
5256
def name(self) -> str:
5357
return "mamba"
5458

src/appose/builder/pixi.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ def __init__(self):
5050
self.conda_packages: list[str] = []
5151
self.pypi_packages: list[str] = []
5252

53+
# Note: Already assigned in BaseBuilder, but stubgen wants these here, too.
54+
self.source_content: str | None = None
55+
self.scheme: str | None = None
56+
5357
def name(self) -> str:
5458
return "pixi"
5559

src/appose/builder/uv.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ def __init__(self):
5151
self.python_version: str | None = None
5252
self.packages: list[str] = []
5353

54+
# Note: Already assigned in BaseBuilder, but stubgen wants these here, too.
55+
self.source_content: str | None = None
56+
self.scheme: str | None = None
57+
5458
def name(self) -> str:
5559
return "uv"
5660

src/appose/service.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class TaskException(Exception):
5555

5656
def __init__(self, message: str, task: "Task") -> None:
5757
super().__init__(message)
58-
self.task = task
58+
self.task: Task = task
5959

6060
@property
6161
def status(self) -> "TaskStatus":

src/appose/shm.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class which can be used with a `with` statement. When the program flow
4949
`unlink_on_dispose` flag.
5050
"""
5151

52-
def __init__(self, name: str = None, create: bool = False, rsize: int = 0):
52+
def __init__(self, name: str | None = None, create: bool = False, rsize: int = 0):
5353
"""
5454
Create a new shared memory block, or attach to an existing one.
5555
@@ -146,7 +146,7 @@ class NDArray:
146146
a particular shape, and flattened into SharedMemory.
147147
"""
148148

149-
def __init__(self, dtype: str, shape: list[int], shm: SharedMemory = None):
149+
def __init__(self, dtype: str, shape: list[int], shm: SharedMemory | None = None):
150150
"""
151151
Create an NDArray.
152152
:param dtype: The type of the data elements; e.g. int8, uint8, float32, float64.

src/appose/syntax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ def invoke_method(
198198
]
199199

200200

201-
def get(name: str) -> ScriptSyntax:
201+
def get(name: str) -> ScriptSyntax | None:
202202
"""
203203
Detects and returns the script syntax with the given name.
204204

src/appose/tool/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ def __init__(self, name: str, url: str, command: str, rootdir: str):
5858
command: Path to the tool's executable command.
5959
rootdir: Root directory where the tool is installed.
6060
"""
61-
self.name = name
62-
self.url = url
63-
self.command = command
64-
self.rootdir = rootdir
61+
self.name: str = name
62+
self.url: str = url
63+
self.command: str = command
64+
self.rootdir: str = rootdir
6565

6666
# Consumer callbacks
6767
self._output_consumer: Callable[[str], None] | None = None

src/appose/tool/mamba.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ class Mamba(Tool):
9999
"""
100100

101101
# Path where Appose installs Micromamba by default
102-
BASE_PATH = str(Path(filepath.appose_envs_dir()) / ".mamba")
102+
BASE_PATH: str = str(Path(filepath.appose_envs_dir()) / ".mamba")
103103

104104
# The platform string for micromamba download
105-
MICROMAMBA_PLATFORM = _micromamba_platform()
105+
PLATFORM: str | None = _micromamba_platform()
106106

107107
# URL from where Micromamba is downloaded to be installed
108-
MICROMAMBA_URL = (
109-
f"https://micro.mamba.pm/api/micromamba/{MICROMAMBA_PLATFORM}/latest"
110-
if MICROMAMBA_PLATFORM
108+
DOWNLOAD_URL: str | None = (
109+
f"https://micro.mamba.pm/api/micromamba/{PLATFORM}/latest"
110+
if PLATFORM
111111
else None
112112
)
113113

@@ -128,7 +128,7 @@ def __init__(self, rootdir: str | None = None):
128128

129129
command_path = str(Path(root) / mamba_relative_path)
130130

131-
super().__init__("micromamba", self.MICROMAMBA_URL, command_path, root)
131+
super().__init__("micromamba", self.DOWNLOAD_URL, command_path, root)
132132

133133
def _decompress(self, archive: Path) -> None:
134134
"""

src/appose/tool/pixi.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ class Pixi(Tool):
7070
"""
7171

7272
# Pixi version to download
73-
PIXI_VERSION = "v0.58.0"
73+
PIXI_VERSION: str = "v0.58.0"
7474

7575
# Path where Appose installs Pixi by default (.pixi subdirectory thereof)
76-
BASE_PATH = filepath.appose_envs_dir()
76+
BASE_PATH: str = filepath.appose_envs_dir()
7777

7878
# The filename to download for the current platform
79-
PIXI_BINARY = _pixi_binary()
79+
PIXI_BINARY: str | None = _pixi_binary()
8080

8181
# URL from where Pixi is downloaded to be installed
82-
PIXI_URL = (
82+
DOWNLOAD_URL: str | None = (
8383
f"https://github.com/prefix-dev/pixi/releases/download/{PIXI_VERSION}/{PIXI_BINARY}"
8484
if PIXI_BINARY
8585
else None
@@ -102,7 +102,7 @@ def __init__(self, rootdir: str | None = None):
102102

103103
command_path = str(Path(root) / pixi_relative_path)
104104

105-
super().__init__("pixi", self.PIXI_URL, command_path, root)
105+
super().__init__("pixi", self.DOWNLOAD_URL, command_path, root)
106106

107107
def _decompress(self, archive: Path) -> None:
108108
"""

0 commit comments

Comments
 (0)