@@ -184,6 +184,7 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
184
184
}
185
185
}
186
186
187
+ ModuleObject mod ;
187
188
string mod_name = Runtime . GetManagedString ( py_mod_name ) ;
188
189
// Check these BEFORE the built-in import runs; may as well
189
190
// 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)
237
238
if ( res != IntPtr . Zero )
238
239
{
239
240
// There was no error.
241
+ if ( fromlist && IsLoadAll ( fromList ) )
242
+ {
243
+ mod = ManagedType . GetManagedObject ( res ) as ModuleObject ;
244
+ mod ? . LoadNames ( ) ;
245
+ }
240
246
return res ;
241
247
}
242
248
// There was an error
@@ -290,6 +296,11 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
290
296
{
291
297
if ( fromlist )
292
298
{
299
+ if ( IsLoadAll ( fromList ) )
300
+ {
301
+ mod = ManagedType . GetManagedObject ( module ) as ModuleObject ;
302
+ mod ? . LoadNames ( ) ;
303
+ }
293
304
Runtime . XIncref ( module ) ;
294
305
return module ;
295
306
}
@@ -345,20 +356,31 @@ public static IntPtr __import__(IntPtr self, IntPtr args, IntPtr kw)
345
356
}
346
357
}
347
358
348
- ModuleObject mod = fromlist ? tail : head ;
359
+ mod = fromlist ? tail : head ;
349
360
350
- if ( fromlist && Runtime . PySequence_Size ( fromList ) == 1 )
361
+ if ( fromlist && IsLoadAll ( fromList ) )
351
362
{
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 ( ) ;
358
364
}
359
365
360
366
Runtime . XIncref ( mod . pyHandle ) ;
361
367
return mod . pyHandle ;
362
368
}
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
+ }
363
385
}
364
386
}
0 commit comments