Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2ae4dbe

Browse files
author
Barton Cline
committed
Dotted "CLR" deprecation detects before built-in __import__ call.
1 parent 0163b0d commit 2ae4dbe

File tree

1 file changed

+21
-20
lines changed

1 file changed

+21
-20
lines changed

pythonnet/src/runtime/importhook.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -113,33 +113,34 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw) {
113113
Runtime.Incref(root.pyHandle);
114114
return root.pyHandle;
115115
}
116-
// 2010-08-15: Always seemed smart to let python try first...
117-
// This shaves off a few tenths of a second on test_module.py
118-
// and works around a quirk where 'sys' is found by the
119-
// LoadImplicit() deprecation logic.
120-
// Turns out that the AssemblyManager.ResolveHandler() checks to see if any
121-
// Assembly's FullName.ToLower().StartsWith(name.ToLower()), which makes very
122-
// little sense to me.
123-
IntPtr res = Runtime.PyObject_Call(py_import, args, kw);
124-
if (res != IntPtr.Zero) {
125-
// There was no error.
126-
return res;
127-
}
128-
// There was an error
129-
if (!Exceptions.ExceptionMatches(Exceptions.ImportError)) {
130-
// and it was NOT an ImportError; bail out here.
131-
return IntPtr.Zero;
132-
}
133-
// Otherwise, just clear the it.
134-
Exceptions.Clear();
135-
136116
string realname = mod_name;
137117
if (mod_name.StartsWith("CLR.")) {
138118
realname = mod_name.Substring(4);
139119
string msg = String.Format("Importing from the CLR.* namespace "+
140120
"is deprecated. Please import '{0}' directly.", realname);
141121
Exceptions.deprecation(msg);
142122
}
123+
else {
124+
// 2010-08-15: Always seemed smart to let python try first...
125+
// This shaves off a few tenths of a second on test_module.py
126+
// and works around a quirk where 'sys' is found by the
127+
// LoadImplicit() deprecation logic.
128+
// Turns out that the AssemblyManager.ResolveHandler() checks to see if any
129+
// Assembly's FullName.ToLower().StartsWith(name.ToLower()), which makes very
130+
// little sense to me.
131+
IntPtr res = Runtime.PyObject_Call(py_import, args, kw);
132+
if (res != IntPtr.Zero) {
133+
// There was no error.
134+
return res;
135+
}
136+
// There was an error
137+
if (!Exceptions.ExceptionMatches(Exceptions.ImportError)) {
138+
// and it was NOT an ImportError; bail out here.
139+
return IntPtr.Zero;
140+
}
141+
// Otherwise, just clear the it.
142+
Exceptions.Clear();
143+
}
143144

144145
string[] names = realname.Split('.');
145146

0 commit comments

Comments
 (0)