summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2021-07-28 13:04:38 (GMT)
committerGitHub <noreply@github.com>2021-07-28 13:04:38 (GMT)
commit684eb5cb8016546f1f8652dae8febd5c6571193e (patch)
treee97d94cf3b4c43787c9bafb21cf3826b4671160b /Lib
parent5502ee052fb4257ad7438dd1130c80e1a9c4bc7f (diff)
downloadcpython-684eb5cb8016546f1f8652dae8febd5c6571193e.zip
cpython-684eb5cb8016546f1f8652dae8febd5c6571193e.tar.gz
cpython-684eb5cb8016546f1f8652dae8febd5c6571193e.tar.bz2
[3.10] bpo-44461: Check early that a pdb target is valid for execution. (GH-27227) (GH-27399)
Automerge-Triggered-By: GH:jaraco
Diffstat (limited to 'Lib')
-rwxr-xr-xLib/pdb.py8
-rw-r--r--Lib/test/test_pdb.py14
2 files changed, 22 insertions, 0 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py
index 1b4ff54..9432111 100755
--- a/Lib/pdb.py
+++ b/Lib/pdb.py
@@ -1694,6 +1694,14 @@ def main():
print('Error:', mainpyfile, 'does not exist')
sys.exit(1)
+ if run_as_module:
+ import runpy
+ try:
+ runpy._get_module_details(mainpyfile)
+ except Exception:
+ traceback.print_exc()
+ sys.exit(1)
+
sys.argv[:] = args # Hide "pdb.py" and pdb options from argument list
if not run_as_module:
diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py
index 63afb81..a9afca8 100644
--- a/Lib/test/test_pdb.py
+++ b/Lib/test/test_pdb.py
@@ -1695,6 +1695,20 @@ def bœr():
self.assertIn("ImportError: No module named t_main.__main__",
stdout.splitlines())
+ def test_package_without_a_main(self):
+ pkg_name = 't_pkg'
+ module_name = 't_main'
+ os_helper.rmtree(pkg_name)
+ modpath = pkg_name + '/' + module_name
+ os.makedirs(modpath)
+ with open(modpath + '/__init__.py', 'w') as f:
+ pass
+ self.addCleanup(os_helper.rmtree, pkg_name)
+ stdout, stderr = self._run_pdb(['-m', modpath.replace('/', '.')], "")
+ self.assertIn(
+ "'t_pkg.t_main' is a package and cannot be directly executed",
+ stdout)
+
def test_blocks_at_first_code_line(self):
script = """
#This is a comment, on line 2