Skip to content

Commit f92e95b

Browse files
committed
cleanup and changelog entry
1 parent 279b535 commit f92e95b

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru
5050
- .NET and Python exceptions are preserved when crossing Python/.NET boundary
5151
- BREAKING: custom encoders are no longer called for instances of `System.Type`
5252
- `PythonException.Restore` no longer clears `PythonException` instance.
53+
- Replaced the old `__import__` hook hack with a PEP302-style Meta Path Loader
5354

5455
### Fixed
5556

@@ -72,6 +73,7 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru
7273
- Providing an invalid type parameter to a generic type or method produces a helpful Python error
7374
- Empty parameter names (as can be generated from F#) do not cause crashes
7475

76+
7577
### Removed
7678

7779
- implicit assembly loading (you have to explicitly `clr.AddReference` before doing import)

src/runtime/importhook.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@ namespace Python.Runtime
88
/// </summary>
99
internal static class ImportHook
1010
{
11-
private static IntPtr py_import;
1211
private static CLRModule root;
13-
private static MethodWrapper hook;
1412
private static IntPtr py_clr_module;
1513
static BorrowedReference ClrModuleReference => new BorrowedReference(py_clr_module);
1614

@@ -25,20 +23,13 @@ def __init__(self):
2523
2624
@classmethod
2725
def exec_module(klass, mod):
28-
# this method is needed to mark this
29-
# loader as a non-legacy loader.
26+
# This method needs to exist.
3027
pass
3128
3229
@classmethod
3330
def create_module(klass, spec):
3431
import clr
35-
a = clr._LoadClrModule(spec)
36-
#mod = getattr(clr, '__imported')
37-
print(a)
38-
#print(mod)
39-
#print(mod is a)
40-
#delattr(clr, '__imported')
41-
return a
32+
return clr._LoadClrModule(spec)
4233
4334
class DotNetFinder(importlib.abc.MetaPathFinder):
4435
@@ -49,9 +40,7 @@ def __init__(self):
4940
@classmethod
5041
def find_spec(klass, fullname, paths=None, target=None):
5142
import clr
52-
# print(clr._availableNamespaces)
5343
if (hasattr(clr, '_availableNamespaces') and fullname in clr._availableNamespaces):
54-
#if (clr._NamespaceLoaded(fullname)):
5544
return importlib.machinery.ModuleSpec(fullname, DotNetLoader(), is_package=True)
5645
return None
5746

src/runtime/moduleobject.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,11 @@ public static int _AtExit()
588588
[ForbidPythonThreads]
589589
public static PyObject _LoadClrModule(PyObject spec)
590590
{
591-
var mod = ImportHook.__import__(spec.GetAttr("name").ToString());
591+
ModuleObject mod = null;
592+
using (var modname = spec.GetAttr("name"))
593+
{
594+
mod = ImportHook.__import__(modname.ToString());
595+
}
592596
// We can't return directly a ModuleObject, because the tpHandle is
593597
// not set, but we can return a PyObject.
594598
return new PyObject(mod.pyHandle);

0 commit comments

Comments
 (0)