@@ -184,6 +184,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
184184 }
185185 }
186186
187+ ModuleObject mod ;
187188 string mod_name = Runtime . GetManagedString ( py_mod_name ) ;
188189 // Check these BEFORE the built-in import runs; may as well
189190 // do the Incref()ed return here, since we've already found
@@ -237,6 +238,11 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
237238 if ( res != IntPtr . Zero )
238239 {
239240 // There was no error.
241+ if ( fromlist && IsLoadAll ( fromList ) )
242+ {
243+ mod = ManagedType . GetManagedObject ( res ) as ModuleObject ;
244+ mod ? . LoadNames ( ) ;
245+ }
240246 return res ;
241247 }
242248 // There was an error
@@ -290,6 +296,11 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
290296 {
291297 if ( fromlist )
292298 {
299+ if ( IsLoadAll ( fromList ) )
300+ {
301+ mod = ManagedType . GetManagedObject ( module ) as ModuleObject ;
302+ mod ? . LoadNames ( ) ;
303+ }
293304 Runtime . XIncref ( module ) ;
294305 return module ;
295306 }
@@ -345,20 +356,31 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
345356 }
346357 }
347358
348- ModuleObject mod = fromlist ? tail : head ;
359+ mod = fromlist ? tail : head ;
349360
350- if ( fromlist && Runtime . PySequence_Size ( fromList ) == 1 )
361+ if ( fromlist && IsLoadAll ( fromList ) )
351362 {
352- IntPtr fp = Runtime . PySequence_GetItem ( fromList , 0 ) ;
353- if ( ! CLRModule . preload && Runtime . GetManagedString ( fp ) == "*" )
354- {
355- mod . LoadNames ( ) ;
356- }
357- Runtime . XDecref ( fp ) ;
363+ mod . LoadNames ( ) ;
358364 }
359365
360366 Runtime . XIncref ( mod . pyHandle ) ;
361367 return mod . pyHandle ;
362368 }
369+
370+ private static bool IsLoadAll ( IntPtr fromList )
371+ {
372+ if ( CLRModule . preload )
373+ {
374+ return false ;
375+ }
376+ if ( Runtime . PySequence_Size ( fromList ) != 1 )
377+ {
378+ return false ;
379+ }
380+ IntPtr fp = Runtime . PySequence_GetItem ( fromList , 0 ) ;
381+ bool res = Runtime . GetManagedString ( fp ) == "*" ;
382+ Runtime . XDecref ( fp ) ;
383+ return res ;
384+ }
363385 }
364386}
0 commit comments