@@ -68,6 +68,7 @@ def _run_code(code, run_globals, init_globals=None,
6868 run_globals .update (__name__ = mod_name ,
6969 __file__ = mod_fname ,
7070 __cached__ = None ,
71+ __doc__ = None ,
7172 __loader__ = mod_loader ,
7273 __package__ = pkg_name )
7374 exec (code , run_globals )
@@ -242,12 +243,14 @@ def run_path(path_name, init_globals=None, run_name=None):
242243 """
243244 if run_name is None :
244245 run_name = "<run_path>"
246+ pkg_name = run_name .rpartition ("." )[0 ]
245247 importer = _get_importer (path_name )
246248 if isinstance (importer , imp .NullImporter ):
247249 # Not a valid sys.path entry, so run the code directly
248250 # execfile() doesn't help as we want to allow compiled files
249251 code = _get_code_from_file (path_name )
250- return _run_module_code (code , init_globals , run_name , path_name )
252+ return _run_module_code (code , init_globals , run_name , path_name ,
253+ pkg_name = pkg_name )
251254 else :
252255 # Importer is defined for path, so add it to
253256 # the start of sys.path
@@ -266,7 +269,6 @@ def run_path(path_name, init_globals=None, run_name=None):
266269 mod_name , loader , code , fname = _get_main_module_details ()
267270 finally :
268271 sys .modules [main_name ] = saved_main
269- pkg_name = ""
270272 with _TempModule (run_name ) as temp_module , \
271273 _ModifiedArgv0 (path_name ):
272274 mod_globals = temp_module .module .__dict__
0 commit comments