This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author remi.lapeyre
Recipients Kerrick Staley, remi.lapeyre
Date 2020-06-01.18:34:50
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1591036490.66.0.55644475132.issue40403@roundup.psfhosted.org>
In-reply-to
Content
I've looked into this, in Bdb both the part where the code is compiled and the one where the code is run are in the run() method (https://github.com/python/cpython/blob/master/Lib/bdb.py#L565-L585):


    def run(self, cmd, globals=None, locals=None):
        """Debug a statement executed via the exec() function.
        globals defaults to __main__.dict; locals defaults to globals.
        """
        if globals is None:
            import __main__
            globals = __main__.__dict__
        if locals is None:
            locals = globals
        self.reset()
        if isinstance(cmd, str):
            cmd = compile(cmd, "<string>", "exec")
        sys.settrace(self.trace_dispatch)
        try:
            exec(cmd, globals, locals)
        except BdbQuit:
            pass
        finally:
            self.quitting = True
            sys.settrace(None)


This is an issue as SyntaxError may come from two lines

 - the call to compile() which means the code being run is not valid Python, in this case the current behaviour of PDB to exit is correct as there is nothing to debug
 - the call to exec() in which case a SyntaxError can happen like in the report, and PDB should go in post mortem debug mode.


One way to fix the issue would be to catch the error in compile() and wrap it in a BdbSyntaxError so that PDB can differentiate between the two, another to keep BDB as it is and change PDB so that it compiles the code first, and call run() in a second step. I think the last one is better and will start writing a PR for this.
History
Date User Action Args
2020-06-01 18:34:50remi.lapeyresetrecipients: + remi.lapeyre, Kerrick Staley
2020-06-01 18:34:50remi.lapeyresetmessageid: <1591036490.66.0.55644475132.issue40403@roundup.psfhosted.org>
2020-06-01 18:34:50remi.lapeyrelinkissue40403 messages
2020-06-01 18:34:50remi.lapeyrecreate