Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 8 Lib/pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
14 changes: 14 additions & 0 deletions 14 Lib/test/test_pdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,20 @@ def test_module_without_a_main(self):
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'
support.rmtree(pkg_name)
modpath = pkg_name + '/' + module_name
os.makedirs(modpath)
with open(modpath + '/__init__.py', 'w') as f:
pass
self.addCleanup(support.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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix bug with :mod:`pdb`'s handling of import error due to a package which does not have a ``__main__`` module
Morty Proxy This is a proxified and sanitized view of the page, visit original site.