Author jaraco
Recipients iritkatriel, jaraco
Date 2021-07-02.20:47:01
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
While investigating issue44461, I observed some complexities to the current pdb.main implementation, some of which likely contributed to the bug being present.

- variables are initialized to defaults ( and then mutated ( based on other variables.

- mainpyfile is conditionally mutated based on previous values of conditionally mutated variables (

- There are three different blocks of code (,, and that are conditionally run based on run_as_module.

These factors mean that all of these lines of code are entangled in ways that are somewhat difficult to reason about. For example, it's unclear what states have been achieved by the time `pdb._run*` is constructed, or what exceptions may or may not be expected for these calls.

A functional or OO approach would limit the amount of mutation and entanglement (through encapsulation or scoping).

An OO approach would have a protocol or interface that captures the different behaviors required prior to and on invocation of `Pdb._run*`.

For example, the PDB "targets" (script or module) could be modeled as separate classes and provide symmetric interfaces with (possibly degenerate) equivalent operations for each use-case.

To be sure, the code that's present is adequate and in my opinion right on the border of benefiting from a more rigorous abstraction. The current imperative approach is fairly readable and mostly comprehensible. It's only because of the surprise behavior in the reported issue that I propose to step back and contemplate ways to alleviate the concerns above.
Date User Action Args
2021-07-02 20:47:02jaracosetrecipients: + jaraco, iritkatriel
2021-07-02 20:47:02jaracosetmessageid: <>
2021-07-02 20:47:01jaracolinkissue44554 messages
2021-07-02 20:47:01jaracocreate