Skip to content

Commit 1915008

Browse files
committed
cleanup and changelog entry
1 parent 012526a commit 1915008

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
@@ -28,6 +28,7 @@ details about the cause of the failure
2828
to the regular method return value (unless they are passed with `ref` or `out` keyword).
2929
- BREAKING: Drop support for the long-deprecated CLR.* prefix.
3030
- `PyObject` now implements `IEnumerable<PyObject>` in addition to `IEnumerable`
31+
- Replaced the old `__import__` hook hack with a PEP302-style Meta Path Loader
3132

3233
### Fixed
3334

@@ -47,6 +48,7 @@ details about the cause of the failure
4748
- Incorrectly using a non-generic type with type parameters now produces a helpful Python error instead of throwing NullReferenceException
4849
- `import` may now raise errors with more detail than "No module named X"
4950

51+
5052
### Removed
5153

5254
- 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

1614
private static IntPtr module_def = IntPtr.Zero;
@@ -26,20 +24,13 @@ def __init__(self):
2624
2725
@classmethod
2826
def exec_module(klass, mod):
29-
# this method is needed to mark this
30-
# loader as a non-legacy loader.
27+
# This method needs to exist.
3128
pass
3229
3330
@classmethod
3431
def create_module(klass, spec):
3532
import clr
36-
a = clr._LoadClrModule(spec)
37-
#mod = getattr(clr, '__imported')
38-
print(a)
39-
#print(mod)
40-
#print(mod is a)
41-
#delattr(clr, '__imported')
42-
return a
33+
return clr._LoadClrModule(spec)
4334
4435
class DotNetFinder(importlib.abc.MetaPathFinder):
4536
@@ -50,9 +41,7 @@ def __init__(self):
5041
@classmethod
5142
def find_spec(klass, fullname, paths=None, target=None):
5243
import clr
53-
# print(clr._availableNamespaces)
5444
if (hasattr(clr, '_availableNamespaces') and fullname in clr._availableNamespaces):
55-
#if (clr._NamespaceLoaded(fullname)):
5645
return importlib.machinery.ModuleSpec(fullname, DotNetLoader(), is_package=True)
5746
return None
5847

src/runtime/moduleobject.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,11 @@ public static int _AtExit()
599599
[ForbidPythonThreads]
600600
public static PyObject _LoadClrModule(PyObject spec)
601601
{
602-
var mod = ImportHook.__import__(spec.GetAttr("name").ToString());
602+
ModuleObject mod = null;
603+
using (var modname = spec.GetAttr("name"))
604+
{
605+
mod = ImportHook.__import__(modname.ToString());
606+
}
603607
// We can't return directly a ModuleObject, because the tpHandle is
604608
// not set, but we can return a PyObject.
605609
return new PyObject(mod.pyHandle);

0 commit comments

Comments
 (0)