Skip to content

Commit 2287199

Browse files
committed
Fix passing properties to .NET Core init and add type hints
1 parent 807ab22 commit 2287199

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

clr_loader/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_coreclr(
3333

3434
impl = DotnetCoreRuntime(runtime_config=runtime_config, dotnet_root=dotnet_root)
3535
if properties:
36-
for key, value in properties:
36+
for key, value in properties.items():
3737
impl[key] = value
3838

3939
return Runtime(impl)

clr_loader/hostfxr.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ def __init__(self, runtime_config: str, dotnet_root: str):
1616
self._load_func = _get_load_func(self._dll, self._handle)
1717

1818
@property
19-
def dotnet_root(self):
19+
def dotnet_root(self) -> str:
2020
return self._dotnet_root
2121

2222
@property
23-
def is_finalized(self):
23+
def is_finalized(self) -> bool:
2424
return self._is_finalized
2525

2626
def __getitem__(self, key: str) -> str:
@@ -58,7 +58,7 @@ def __iter__(self):
5858
for i in range(size_ptr[0]):
5959
yield (decode(keys_ptr[i]), decode(values_ptr[i]))
6060

61-
def get_callable(self, assembly_path, typename, function):
61+
def get_callable(self, assembly_path: str, typename: str, function: str):
6262
# TODO: Maybe use coreclr_get_delegate as well, supported with newer API
6363
# versions of hostfxr
6464
self._is_finalized = True
@@ -79,7 +79,7 @@ def get_callable(self, assembly_path, typename, function):
7979
check_result(res)
8080
return ffi.cast("component_entry_point_fn", delegate_ptr[0])
8181

82-
def shutdown(self):
82+
def shutdown(self) -> None:
8383
if self._handle is not None:
8484
self._dll.hostfxr_close(self._handle)
8585
self._handle = None
@@ -88,7 +88,7 @@ def __del__(self):
8888
self.shutdown()
8989

9090

91-
def _get_handle(dll, dotnet_root, runtime_config):
91+
def _get_handle(dll, dotnet_root: str, runtime_config: str):
9292
params = ffi.new("hostfxr_initialize_parameters*")
9393
params.size = ffi.sizeof("hostfxr_initialize_parameters")
9494
# params.host_path = ffi.new("char_t[]", encode(sys.executable))

clr_loader/mono.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ def initialize(config_file: str, libmono: str) -> None:
8787
_MONO = load_mono(libmono)
8888

8989
if config_file is None:
90-
config_file = ffi.NULL
90+
config_bytes = ffi.NULL
9191
else:
92-
config_file = config_file.encode("utf8")
92+
config_bytes = config_file.encode("utf8")
9393

9494
_ROOT_DOMAIN = _MONO.mono_jit_init(b"clr_loader")
95-
_MONO.mono_config_parse(config_file)
95+
_MONO.mono_config_parse(config_bytes)
9696
_check_result(_ROOT_DOMAIN, "Failed to initialize Mono")
9797
atexit.register(_release)
9898

clr_loader/netfx.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
import atexit
2+
from typing import Optional, Any
23
from .ffi import ffi, load_netfx
34

4-
_FW = None
5+
_FW: Optional[Any] = None
56

67

78
class NetFx:
8-
def __init__(self, name=None, config_file=None):
9+
def __init__(self, name: Optional[str] = None, config_file: Optional[str] = None):
910
initialize()
1011
self._domain = _FW.pyclr_create_appdomain(
1112
name or ffi.NULL, config_file or ffi.NULL
1213
)
1314

14-
def get_callable(self, assembly_path, typename, function):
15+
def get_callable(self, assembly_path: str, typename: str, function: str):
1516
func = _FW.pyclr_get_function(
1617
self._domain,
1718
assembly_path.encode("utf8"),

0 commit comments

Comments
 (0)