diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2021-07-27 21:51:42 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-27 21:51:42 -0400 |
commit | ee03bad25e83b00ba5fc2a0265b48c6286e6b3f7 (patch) | |
tree | 158d1626a8fe583ee120147abbc649a4e7d21a0a | |
parent | 38ddc8beb38d9a685de296a58b0741850e4853e5 (diff) | |
download | cpython-git-ee03bad25e83b00ba5fc2a0265b48c6286e6b3f7.tar.gz |
bpo-44461: Check early that a pdb target is valid for execution. (#27227)
* bpo-44461: Fix bug with pdb's handling of import error due to a package which does not have a __main__ module
* ðð€ Added by blurb_it.
* remove "else"
Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
* If running as a module, first check that it can run as a module. Alternate fix for bpo-44461.
Co-authored-by: Irit Katriel <iritkatriel@yahoo.com>
Co-authored-by: blurb-it[bot] <43283697+blurb-it[bot]@users.noreply.github.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
-rwxr-xr-x | Lib/pdb.py | 6 | ||||
-rw-r--r-- | Lib/test/test_pdb.py | 14 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2021-06-29-21-17-17.bpo-44461.acqRnV.rst | 1 |
3 files changed, 20 insertions, 1 deletions
diff --git a/Lib/pdb.py b/Lib/pdb.py index e769ad7d26..8aa899f90b 100755 --- a/Lib/pdb.py +++ b/Lib/pdb.py @@ -169,7 +169,11 @@ class ScriptTarget(str): class ModuleTarget(str): def check(self): - pass + try: + self._details + except Exception: + traceback.print_exc() + sys.exit(1) @functools.cached_property def _details(self): diff --git a/Lib/test/test_pdb.py b/Lib/test/test_pdb.py index 5fe75175bf..5794e67aaf 100644 --- a/Lib/test/test_pdb.py +++ b/Lib/test/test_pdb.py @@ -1729,6 +1729,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 diff --git a/Misc/NEWS.d/next/Library/2021-06-29-21-17-17.bpo-44461.acqRnV.rst b/Misc/NEWS.d/next/Library/2021-06-29-21-17-17.bpo-44461.acqRnV.rst new file mode 100644 index 0000000000..02e25e928b --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-06-29-21-17-17.bpo-44461.acqRnV.rst @@ -0,0 +1 @@ +Fix bug with :mod:`pdb`'s handling of import error due to a package which does not have a ``__main__`` module
\ No newline at end of file |