bpo-44461: Fix bug with pdb's handling of import error due to a packa… by iritkatriel · Pull Request #26937 · python/cpython

Really appreciate the PR here and your analysis in the bug. Nice work.

One thing I notice is that .runmodule and .runscript are symmetric operations, and one of the reasons that .reset() isn't invoked is because in .runmodule, the viability of the target (-m package.mod) isn't checked until in the runmodule step, whereas in the file-based approach, the presence of the file is checked early and SyntaxErrors are trapped separately.

Perhaps runmodule should do something similar and handle non-existence of an executable module (here) by raising a distinct exception to be handled separately in the main loop. Then, the conditions that lead to .botframe not being set would never get triggered (similar to how things are handled when a script is missing or has a SyntaxError).

WDYT?