Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions clr_loader/mono.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import Any, Dict, Optional, Sequence

from .ffi import ffi, load_mono
from .types import Runtime, RuntimeInfo
from .types import Runtime, RuntimeInfo, StrOrPath
from .util import optional_path_as_string, path_as_string

__all__ = ["Mono"]
Expand Down Expand Up @@ -32,7 +32,7 @@ def __init__(
):
self._assemblies: Dict[Path, Any] = {}

self._version = initialize(
self._version: str = initialize(
config_file=optional_path_as_string(config_file),
debug=debug,
jit_options=jit_options,
Expand All @@ -50,7 +50,9 @@ def __init__(
else:
raise NotImplementedError

def _get_callable(self, assembly_path, typename, function):
def _get_callable(
self, assembly_path: StrOrPath, typename: str, function: str
) -> "MonoMethod":
assembly_path = Path(assembly_path)
assembly = self._assemblies.get(assembly_path)
if not assembly:
Expand Down Expand Up @@ -87,14 +89,14 @@ def shutdown(self) -> None:


class MethodDesc:
def __init__(self, typename, function):
def __init__(self, typename: str, function: str):
self._desc = f"{typename}:{function}"
self._ptr = _MONO.mono_method_desc_new(
self._desc.encode("utf8"),
1, # include_namespace
)

def search(self, image):
def search(self, image: str):
return _MONO.mono_method_desc_search_in_image(self._ptr, image)

def __del__(self):
Expand Down
6 changes: 3 additions & 3 deletions clr_loader/netfx.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class NetFx(Runtime):
def __init__(
self, domain: Optional[str] = None, config_file: Optional[Path] = None
):
self._domain = None
self._domain: Optional[str] = None

initialize()
if config_file is not None:
Expand All @@ -22,8 +22,8 @@ def __init__(

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

self._domain_name = domain
self._config_file = config_file
self._domain_name: Optional[str] = domain
self._config_file: Optional[Path] = config_file
self._domain = _FW.pyclr_create_appdomain(domain_s, config_file_s)

def info(self) -> RuntimeInfo:
Expand Down
17 changes: 10 additions & 7 deletions clr_loader/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@

__all__ = ["StrOrPath"]

StrOrPath = Union[str, PathLike]
try:
StrOrPath = Union[str, PathLike[str]]
except TypeError:
StrOrPath = Union[str, PathLike]


@dataclass
Expand Down Expand Up @@ -34,7 +37,7 @@ class RuntimeInfo:

def __str__(self) -> str:
return (
f"Runtime: {self.kind}\n"
f"Runtime: {self.kind}\n" # pyright: ignore[reportImplicitStringConcatenation]
"=============\n"
f" Version: {self.version}\n"
f" Initialized: {self.initialized}\n"
Expand All @@ -51,9 +54,9 @@ class ClrFunction:
def __init__(
self, runtime: "Runtime", assembly: StrOrPath, typename: str, func_name: str
):
self._assembly = assembly
self._class = typename
self._name = func_name
self._assembly: StrOrPath = assembly
self._class: str = typename
self._name: str = func_name

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

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

class Assembly:
def __init__(self, runtime: "Runtime", path: StrOrPath):
self._runtime = runtime
self._path = path
self._runtime: "Runtime" = runtime
self._path: StrOrPath = path

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