@@ -124,7 +124,7 @@ internal static void Shutdown()
124124
125125 internal static void SaveRuntimeData ( RuntimeDataStorage storage )
126126 {
127- // Increment the reference counts here so that the objects don't
127+ // Increment the reference counts here so that the objects don't
128128 // get freed in Shutdown.
129129 Runtime . XIncref ( py_clr_module ) ;
130130 Runtime . XIncref ( root . pyHandle ) ;
@@ -241,12 +241,8 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
241241 // Check these BEFORE the built-in import runs; may as well
242242 // do the Incref()ed return here, since we've already found
243243 // the module.
244- if ( mod_name == "clr" || mod_name == "CLR" )
244+ if ( mod_name == "clr" )
245245 {
246- if ( mod_name == "CLR" )
247- {
248- Exceptions . deprecation ( "The CLR module is deprecated. Please use 'clr'." ) ;
249- }
250246 IntPtr clr_module = GetCLRModule ( fromList ) ;
251247 if ( clr_module != IntPtr . Zero )
252248 {
@@ -262,51 +258,41 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
262258 string realname = mod_name ;
263259 string clr_prefix = null ;
264260
265- if ( mod_name . StartsWith ( "CLR." ) )
261+ // 2010-08-15: Always seemed smart to let python try first...
262+ // This shaves off a few tenths of a second on test_module.py
263+ // and works around a quirk where 'sys' is found by the
264+ // LoadImplicit() deprecation logic.
265+ // Turns out that the AssemblyManager.ResolveHandler() checks to see if any
266+ // Assembly's FullName.ToLower().StartsWith(name.ToLower()), which makes very
267+ // little sense to me.
268+ IntPtr res = Runtime . PyObject_Call ( py_import , args , kw ) ;
269+ if ( res != IntPtr . Zero )
266270 {
267- clr_prefix = "CLR." ; // prepend when adding the module to sys.modules
268- realname = mod_name . Substring ( 4 ) ;
269- string msg = $ "Importing from the CLR.* namespace is deprecated. Please import '{ realname } ' directly.";
270- Exceptions . deprecation ( msg ) ;
271- }
272- else
273- {
274- // 2010-08-15: Always seemed smart to let python try first...
275- // This shaves off a few tenths of a second on test_module.py
276- // and works around a quirk where 'sys' is found by the
277- // LoadImplicit() deprecation logic.
278- // Turns out that the AssemblyManager.ResolveHandler() checks to see if any
279- // Assembly's FullName.ToLower().StartsWith(name.ToLower()), which makes very
280- // little sense to me.
281- IntPtr res = Runtime . PyObject_Call ( py_import , args , kw ) ;
282- if ( res != IntPtr . Zero )
271+ // There was no error.
272+ if ( fromlist && IsLoadAll ( fromList ) )
283273 {
284- // There was no error.
285- if ( fromlist && IsLoadAll ( fromList ) )
286- {
287- var mod = ManagedType . GetManagedObject ( res ) as ModuleObject ;
288- mod ? . LoadNames ( ) ;
289- }
290- return res ;
291- }
292- // There was an error
293- if ( ! Exceptions . ExceptionMatches ( Exceptions . ImportError ) )
294- {
295- // and it was NOT an ImportError; bail out here.
296- return IntPtr . Zero ;
274+ var mod = ManagedType . GetManagedObject ( res ) as ModuleObject ;
275+ mod ? . LoadNames ( ) ;
297276 }
277+ return res ;
278+ }
279+ // There was an error
280+ if ( ! Exceptions . ExceptionMatches ( Exceptions . ImportError ) )
281+ {
282+ // and it was NOT an ImportError; bail out here.
283+ return IntPtr . Zero ;
284+ }
298285
299- if ( mod_name == string . Empty )
300- {
301- // Most likely a missing relative import.
302- // For example site-packages\bs4\builder\__init__.py uses it to check if a package exists:
303- // from . import _html5lib
304- // We don't support them anyway
305- return IntPtr . Zero ;
306- }
307- // Otherwise, just clear the it.
308- Exceptions . Clear ( ) ;
286+ if ( mod_name == string . Empty )
287+ {
288+ // Most likely a missing relative import.
289+ // For example site-packages\bs4\builder\__init__.py uses it to check if a package exists:
290+ // from . import _html5lib
291+ // We don't support them anyway
292+ return IntPtr . Zero ;
309293 }
294+ // Otherwise, just clear the it.
295+ Exceptions . Clear ( ) ;
310296
311297 string [ ] names = realname . Split ( '.' ) ;
312298
@@ -372,7 +358,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
372358 // Add the module to sys.modules
373359 Runtime . PyDict_SetItemString ( modules , tail . moduleName , tail . pyHandle ) ;
374360
375- // If imported from CLR add CLR .<modulename> to sys.modules as well
361+ // If imported from CLR add clr .<modulename> to sys.modules as well
376362 if ( clr_prefix != null )
377363 {
378364 Runtime . PyDict_SetItemString ( modules , clr_prefix + tail . moduleName , tail . pyHandle ) ;
0 commit comments