classification
Title: pdb: "debug print(" crashes with SyntaxError
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.8, Python 3.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: blueyed, eamanu, lukasz.langa, miss-islington, ned.deily, remi.lapeyre, zach.ware
Priority: normal Keywords: patch, patch

Created on 2019-02-07 16:02 by blueyed, last changed 2019-03-12 04:02 by zach.ware. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 11782 merged blueyed, 2019-02-07 16:03
PR 11782 merged blueyed, 2019-02-07 16:03
PR 11886 merged miss-islington, 2019-02-15 20:53
PR 12103 merged blueyed, 2019-02-28 18:25
PR 12285 merged miss-islington, 2019-03-12 03:29
Messages (12)
msg335025 - (view) Author: daniel hahler (blueyed) * Date: 2019-02-07 16:02
`debug print(` will make pdb crash with a SyntaxError:

    % python -c '__import__("pdb").set_trace()'          
    --Return--
    > <string>(1)<module>()->None
    (Pdb) print(
    *** SyntaxError: unexpected EOF while parsing
    (Pdb) debug print(
    ENTERING RECURSIVE DEBUGGER
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib64/python3.7/bdb.py", line 92, in trace_dispatch
        return self.dispatch_return(frame, arg)
      File "/usr/lib64/python3.7/bdb.py", line 151, in dispatch_return
        self.user_return(frame, arg)
      File "/usr/lib64/python3.7/pdb.py", line 293, in user_return
        self.interaction(frame, None)
      File "/usr/lib64/python3.7/pdb.py", line 352, in interaction
        self._cmdloop()
      File "/usr/lib64/python3.7/pdb.py", line 321, in _cmdloop
        self.cmdloop()
      File "/usr/lib64/python3.7/cmd.py", line 138, in cmdloop
        stop = self.onecmd(line)
      File "/usr/lib64/python3.7/pdb.py", line 418, in onecmd
        return cmd.Cmd.onecmd(self, line)
      File "/usr/lib64/python3.7/cmd.py", line 217, in onecmd
        return func(arg)
      File "/usr/lib64/python3.7/pdb.py", line 1099, in do_debug
        sys.call_tracing(p.run, (arg, globals, locals))
      File "/usr/lib64/python3.7/bdb.py", line 582, in run
        cmd = compile(cmd, "<string>", "exec")
      File "<string>", line 1
        print(
             ^
    SyntaxError: unexpected EOF while parsing
msg335643 - (view) Author: Emmanuel Arias (eamanu) * Date: 2019-02-15 19:40
ping reviewer :-)

I test this PR and work fine on Ubuntu 18.04
msg335645 - (view) Author: miss-islington (miss-islington) Date: 2019-02-15 20:52
New changeset 4327705cfab3eb09073ec828570bbd8f789e1611 by Miss Islington (bot) (Daniel Hahler) in branch 'master':
bpo-35931: Gracefully handle SyntaxError in pdb debug command (GH-11782)
https://github.com/python/cpython/commit/4327705cfab3eb09073ec828570bbd8f789e1611
msg335646 - (view) Author: miss-islington (miss-islington) Date: 2019-02-15 21:19
New changeset 6f352199e4447764bc472e34352d0dff4db8a52d by Miss Islington (bot) in branch '3.7':
bpo-35931: Gracefully handle SyntaxError in pdb debug command (GH-11782)
https://github.com/python/cpython/commit/6f352199e4447764bc472e34352d0dff4db8a52d
msg335647 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-02-15 21:20
Thanks for the patch!
msg335649 - (view) Author: daniel hahler (blueyed) * Date: 2019-02-15 21:48
Thanks for the review and backport!
msg336862 - (view) Author: daniel hahler (blueyed) * Date: 2019-02-28 18:10
Re-opening: it currently still crashes with a NameError when using "debug doesnotexist", or "debug doesnotexist()".

Will create a new PR for this.
msg337575 - (view) Author: daniel hahler (blueyed) * Date: 2019-03-09 17:29
Bumping.

The first (merged) patch is not sufficient, and causes even an API breakage, because it disallows passing in a code object (via compile()) anymore.

A better fix is waiting at https://github.com/python/cpython/pull/12103, and should also get backported to for 3.7.3 then (or the first backport being reverted).
msg337576 - (view) Author: daniel hahler (blueyed) * Date: 2019-03-09 17:40
Example of the API breakage:

```
/opt/python/3.8-dev/lib/python3.8/pdb.py:321: in _cmdloop
    self.cmdloop()
/opt/python/3.8-dev/lib/python3.8/cmd.py:138: in cmdloop
    stop = self.onecmd(line)
/opt/python/3.8-dev/lib/python3.8/pdb.py:418: in onecmd
    return cmd.Cmd.onecmd(self, line)
/opt/python/3.8-dev/lib/python3.8/cmd.py:217: in onecmd
    return func(arg)
pdb.py:699: in do_debug
    return orig_do_debug(self, cmd)
/opt/python/3.8-dev/lib/python3.8/pdb.py:1097: in do_debug
    code = compile(arg, "<string>", "exec")
E   TypeError: compile() arg 1 must be a string, bytes or AST object
```

(via https://travis-ci.org/antocuni/pdb/jobs/504061679#L367)
msg337714 - (view) Author: miss-islington (miss-islington) Date: 2019-03-12 03:29
New changeset 3e936431e23b424b1e4665e8165c245924f0ab02 by Miss Islington (bot) (Daniel Hahler) in branch 'master':
bpo-35931: Gracefully handle any exception in pdb debug command (GH-12103)
https://github.com/python/cpython/commit/3e936431e23b424b1e4665e8165c245924f0ab02
msg337716 - (view) Author: miss-islington (miss-islington) Date: 2019-03-12 04:01
New changeset 1c4580d1f563173f5d6ec990b46bd38f4ae901a1 by Miss Islington (bot) in branch '3.7':
[3.7] bpo-35931: Gracefully handle any exception in pdb debug command (GH-12103) (GH-12285)
https://github.com/python/cpython/commit/1c4580d1f563173f5d6ec990b46bd38f4ae901a1
msg337717 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2019-03-12 04:02
Thanks for catching that and fixing it before 3.7.3!
History
Date User Action Args
2019-03-12 04:02:55zach.waresetstatus: open -> closed
priority: release blocker -> normal

keywords: patch, patch
messages: + msg337717
type: behavior
resolution: fixed
stage: patch review -> resolved
2019-03-12 04:01:04miss-islingtonsetmessages: + msg337716
2019-03-12 03:29:14miss-islingtonsetpull_requests: + pull_request12264
2019-03-12 03:29:06miss-islingtonsetmessages: + msg337714
2019-03-09 17:40:37blueyedsetmessages: + msg337576
2019-03-09 17:32:00ned.deilysetkeywords: patch, patch
priority: normal -> release blocker

nosy: + ned.deily, lukasz.langa
2019-03-09 17:29:19blueyedsetresolution: fixed -> (no value)
messages: + msg337575
2019-02-28 18:25:55blueyedsetstage: resolved -> patch review
pull_requests: + pull_request12109
2019-02-28 18:10:46blueyedsetstatus: closed -> open

messages: + msg336862
2019-02-15 21:48:44blueyedsetmessages: + msg335649
2019-02-15 21:20:40zach.waresetstatus: open -> closed

versions: + Python 3.7
keywords: patch, patch
nosy: + zach.ware

messages: + msg335647
resolution: fixed
stage: patch review -> resolved
2019-02-15 21:19:48miss-islingtonsetmessages: + msg335646
2019-02-15 20:53:12miss-islingtonsetpull_requests: + pull_request11916
2019-02-15 20:52:56miss-islingtonsetnosy: + miss-islington
messages: + msg335645
2019-02-15 19:40:39eamanusetnosy: + eamanu
messages: + msg335643
2019-02-08 00:40:47remi.lapeyresetnosy: + remi.lapeyre
2019-02-07 16:03:46blueyedsetkeywords: + patch
stage: patch review
pull_requests: + pull_request11768
2019-02-07 16:03:42blueyedsetkeywords: + patch
stage: (no value)
pull_requests: + pull_request11767
2019-02-07 16:02:51blueyedcreate