cpython: fccd733aa78b (original) (raw)

--- a/Lib/runpy.py +++ b/Lib/runpy.py @@ -114,6 +114,15 @@ def _get_module_details(mod_name, error= if e.name is None or (e.name != pkg_name and not pkg_name.startswith(e.name + ".")): raise

try: spec = importlib.util.find_spec(mod_name) @@ -121,7 +130,7 @@ def _get_module_details(mod_name, error= # This hack fixes an impedance mismatch between pkgutil and # importlib, where the latter raises other errors for cases where # pkgutil previously raised ImportError

--- a/Lib/test/test_cmd_line_script.py +++ b/Lib/test/test_cmd_line_script.py @@ -425,8 +425,9 @@ class CmdLineTest(unittest.TestCase): # Exercise error reporting for various invalid package executions tests = ( ('builtins', br'No code object available'),

@@ -449,7 +450,8 @@ class CmdLineTest(unittest.TestCase): with open('test_pkg/init.pyc', 'wb'): pass err = self.check_dash_m_failure('test_pkg')

--- a/Lib/test/test_runpy.py +++ b/Lib/test/test_runpy.py @@ -7,6 +7,7 @@ import re import tempfile import importlib, importlib.machinery, importlib.util import py_compile +import warnings from test.support import ( forget, make_legacy_pyc, unload, verbose, no_tracing, create_empty_file, temp_dir) @@ -246,7 +247,7 @@ class RunModuleTestCase(unittest.TestCas mod_fname) return pkg_dir, mod_fname, mod_name, mod_spec

@@ -320,7 +321,7 @@ class RunModuleTestCase(unittest.TestCas self._fix_ns_for_legacy_pyc(expected_ns, alter_sys) self.check_code_execution(create_ns, expected_ns) finally:

def _check_package(self, depth, alter_sys=False, @@ -361,7 +362,7 @@ class RunModuleTestCase(unittest.TestCas self._fix_ns_for_legacy_pyc(expected_ns, alter_sys) self.check_code_execution(create_ns, expected_ns) finally:

def _add_relative_modules(self, base_dir, source, depth): @@ -424,7 +425,7 @@ from ..uncle.cousin import nephew self.assertIn("nephew", d2) del d2 # Ensure loader entry doesn't keep file open finally:

def test_run_module(self): @@ -447,7 +448,7 @@ from ..uncle.cousin import nephew result = self._make_pkg("", 1, "main") pkg_dir, _, mod_name, _ = result mod_name = mod_name.replace(".main", "")

exceptions = (ImportError, AttributeError, TypeError, ValueError) @@ -470,6 +471,31 @@ from ..uncle.cousin import nephew else: self.fail("Nothing raised; expected {}".format(name))

+

+ def test_run_package_in_namespace_package(self): for depth in range(1, 4): if verbose > 1: print("Testing package depth:", depth) @@ -524,7 +550,7 @@ from ..uncle.cousin import nephew try: self.check_code_execution(create_ns, expected_ns) finally:

def test_pkgutil_walk_packages(self): # This is a dodgy hack to use the test_runpy infrastructure to test @@ -548,7 +574,7 @@ from ..uncle.cousin import nephew expected_modules.add(pkg_name + ".runpy_test") pkg_dir, mod_fname, mod_name, mod_spec = ( self._make_pkg("", max_depth))

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,10 @@ What's New in Python 3.6.0 beta 1 Core and Builtins ----------------- +- Issue #27487: Warn if a submodule argument to "python -m" or