Skip to content

Commit 718fc48

Browse files
authored
Add a few more type hints (#91)
1 parent 961d1e1 commit 718fc48

File tree

3 files changed

+20
-15
lines changed

3 files changed

+20
-15
lines changed

clr_loader/mono.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from typing import Any, Dict, Optional, Sequence
55

66
from .ffi import ffi, load_mono
7-
from .types import Runtime, RuntimeInfo
7+
from .types import Runtime, RuntimeInfo, StrOrPath
88
from .util import optional_path_as_string, path_as_string
99

1010
__all__ = ["Mono"]
@@ -32,7 +32,7 @@ def __init__(
3232
):
3333
self._assemblies: Dict[Path, Any] = {}
3434

35-
self._version = initialize(
35+
self._version: str = initialize(
3636
config_file=optional_path_as_string(config_file),
3737
debug=debug,
3838
jit_options=jit_options,
@@ -50,7 +50,9 @@ def __init__(
5050
else:
5151
raise NotImplementedError
5252

53-
def _get_callable(self, assembly_path, typename, function):
53+
def _get_callable(
54+
self, assembly_path: StrOrPath, typename: str, function: str
55+
) -> "MonoMethod":
5456
assembly_path = Path(assembly_path)
5557
assembly = self._assemblies.get(assembly_path)
5658
if not assembly:
@@ -87,14 +89,14 @@ def shutdown(self) -> None:
8789

8890

8991
class MethodDesc:
90-
def __init__(self, typename, function):
92+
def __init__(self, typename: str, function: str):
9193
self._desc = f"{typename}:{function}"
9294
self._ptr = _MONO.mono_method_desc_new(
9395
self._desc.encode("utf8"),
9496
1, # include_namespace
9597
)
9698

97-
def search(self, image):
99+
def search(self, image: str):
98100
return _MONO.mono_method_desc_search_in_image(self._ptr, image)
99101

100102
def __del__(self):

clr_loader/netfx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class NetFx(Runtime):
1212
def __init__(
1313
self, domain: Optional[str] = None, config_file: Optional[Path] = None
1414
):
15-
self._domain = None
15+
self._domain: Optional[str] = None
1616

1717
initialize()
1818
if config_file is not None:
@@ -22,8 +22,8 @@ def __init__(
2222

2323
domain_s = domain.encode("utf8") if domain else ffi.NULL
2424

25-
self._domain_name = domain
26-
self._config_file = config_file
25+
self._domain_name: Optional[str] = domain
26+
self._config_file: Optional[Path] = config_file
2727
self._domain = _FW.pyclr_create_appdomain(domain_s, config_file_s)
2828

2929
def info(self) -> RuntimeInfo:

clr_loader/types.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
55

66
__all__ = ["StrOrPath"]
77

8-
StrOrPath = Union[str, PathLike]
8+
try:
9+
StrOrPath = Union[str, PathLike[str]]
10+
except TypeError:
11+
StrOrPath = Union[str, PathLike]
912

1013

1114
@dataclass
@@ -34,7 +37,7 @@ class RuntimeInfo:
3437

3538
def __str__(self) -> str:
3639
return (
37-
f"Runtime: {self.kind}\n"
40+
f"Runtime: {self.kind}\n" # pyright: ignore[reportImplicitStringConcatenation]
3841
"=============\n"
3942
f" Version: {self.version}\n"
4043
f" Initialized: {self.initialized}\n"
@@ -51,9 +54,9 @@ class ClrFunction:
5154
def __init__(
5255
self, runtime: "Runtime", assembly: StrOrPath, typename: str, func_name: str
5356
):
54-
self._assembly = assembly
55-
self._class = typename
56-
self._name = func_name
57+
self._assembly: StrOrPath = assembly
58+
self._class: str = typename
59+
self._name: str = func_name
5760

5861
self._callable = runtime._get_callable(assembly, typename, func_name)
5962

@@ -69,8 +72,8 @@ def __repr__(self) -> str:
6972

7073
class Assembly:
7174
def __init__(self, runtime: "Runtime", path: StrOrPath):
72-
self._runtime = runtime
73-
self._path = path
75+
self._runtime: "Runtime" = runtime
76+
self._path: StrOrPath = path
7477

7578
def get_function(self, name: str, func: Optional[str] = None) -> ClrFunction:
7679
"""Get a wrapped .NET function instance

0 commit comments

Comments
 (0)