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

Skip to content

Commit 761bb11

Browse files
committed
Close #15230: runpy.run_path now sets __package__ correctly. Also refactored the runpy tests to use a more systematic approach
1 parent 2bb3021 commit 761bb11

3 files changed

Lines changed: 277 additions & 158 deletions

File tree

Lib/runpy.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)