| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 279b535 commit f92e95b
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,6 +50,7 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru | |||
| 50 | 50 | - .NET and Python exceptions are preserved when crossing Python/.NET boundary | |
| 51 | 51 | - BREAKING: custom encoders are no longer called for instances of `System.Type` | |
| 52 | 52 | - `PythonException.Restore` no longer clears `PythonException` instance. | |
| 53 | + - Replaced the old `__import__` hook hack with a PEP302-style Meta Path Loader | ||
| 53 | 54 | ||
| 54 | 55 | ### Fixed | |
| 55 | 56 | ||
@@ -72,6 +73,7 @@ One must now either use enum members (e.g. `MyEnum.Option`), or use enum constru | |||
| 72 | 73 | - Providing an invalid type parameter to a generic type or method produces a helpful Python error | |
| 73 | 74 | - Empty parameter names (as can be generated from F#) do not cause crashes | |
| 74 | 75 | ||
| 76 | + | ||
| 75 | 77 | ### Removed | |
| 76 | 78 | ||
| 77 | 79 | - implicit assembly loading (you have to explicitly `clr.AddReference` before doing import) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -8,9 +8,7 @@ namespace Python.Runtime | |||
| 8 | 8 | /// </summary> | |
| 9 | 9 | internal static class ImportHook | |
| 10 | 10 | { | |
| 11 | - private static IntPtr py_import; | ||
| 12 | 11 | private static CLRModule root; | |
| 13 | - private static MethodWrapper hook; | ||
| 14 | 12 | private static IntPtr py_clr_module; | |
| 15 | 13 | static BorrowedReference ClrModuleReference => new BorrowedReference(py_clr_module); | |
| 16 | 14 | ||
@@ -25,20 +23,13 @@ def __init__(self): | |||
| 25 | 23 | ||
| 26 | 24 | @classmethod | |
| 27 | 25 | 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. | ||
| 30 | 27 | pass | |
| 31 | 28 | ||
| 32 | 29 | @classmethod | |
| 33 | 30 | def create_module(klass, spec): | |
| 34 | 31 | 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) | ||
| 42 | 33 | ||
| 43 | 34 | class DotNetFinder(importlib.abc.MetaPathFinder): | |
| 44 | 35 | ||
@@ -49,9 +40,7 @@ def __init__(self): | |||
| 49 | 40 | @classmethod | |
| 50 | 41 | def find_spec(klass, fullname, paths=None, target=None): | |
| 51 | 42 | import clr | |
| 52 | - # print(clr._availableNamespaces) | ||
| 53 | 43 | if (hasattr(clr, '_availableNamespaces') and fullname in clr._availableNamespaces): | |
| 54 | - #if (clr._NamespaceLoaded(fullname)): | ||
| 55 | 44 | return importlib.machinery.ModuleSpec(fullname, DotNetLoader(), is_package=True) | |
| 56 | 45 | return None | |
| 57 | 46 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -588,7 +588,11 @@ public static int _AtExit() | |||
| 588 | 588 | [ForbidPythonThreads] | |
| 589 | 589 | public static PyObject _LoadClrModule(PyObject spec) | |
| 590 | 590 | { | |
| 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 | + } | ||
| 592 | 596 | // We can't return directly a ModuleObject, because the tpHandle is | |
| 593 | 597 | // not set, but we can return a PyObject. | |
| 594 | 598 | return new PyObject(mod.pyHandle); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments