py-up-exception remaining

Bug #913905 reported by Andreas Roehler
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
python-mode.el
Fix Released
Medium
Andreas Roehler

Bug Description

Hi Andreas,

A good improvement. There's still a minor bug with IPython and moving
up the stacks with C-c -. In the demo1.py example, pressing C-c -
repeatedly goes up the stack until the

----> 1 demo1.f()

line is reached, at which point string-match says "wrong-type-argument
stringp nil"; here's the backtrace:

Debugger entered--Lisp error: (wrong-type-argument stringp nil)
  string-match(".+.pyc" nil)
  (if (string-match ".+.pyc" file) (progn (setq file ...)))
  (when (string-match ".+.pyc" file) (setq file (substring file 0 -1)))
  (progn (setq py-last-exeption-buffer (current-buffer)) (if (save-match-data ...) (progn ...) (setq line ... pos ... file ...)) (when (string-match ".+.pyc" file) (setq file ...)) (when (string= errwhere "Bottom") (goto-char pos)) (if (and file line) (if ... ... ...) (error "%s of traceback" errwhere)))
  (if (not (save-match-data ...)) (progn (setq py-last-exeption-buffer ...) (if ... ... ...) (when ... ...) (when ... ...) (if ... ... ...)) (goto-char orig) (error "%s of traceback" errwhere))
  (if (save-match-data (eq ... origline)) (progn (forward-line ...) (py-find-next-exception start buffer searchdir errwhere)) (if (not ...) (progn ... ... ... ... ...) (goto-char orig) (error "%s of traceback" errwhere)))
  (if (funcall searchdir py-traceback-line-re nil t) (if (save-match-data ...) (progn ... ...) (if ... ... ... ...)))
  (let ((orig ...) (origline ...) file line pos) (goto-char (py-point start)) (if (funcall searchdir py-traceback-line-re nil t) (if ... ... ...)))
  py-find-next-exception(bol "*IPython*" re-search-backward "Top")
  (if (string= start "TOP") (py-find-next-exception (quote bob) buffer (quote re-search-forward) "Top") (py-find-next-exception (quote bol) buffer (quote re-search-backward) "Top"))
  (if (eq direction (quote up)) (if (string= start "TOP") (py-find-next-exception ... buffer ... "Top") (py-find-next-exception ... buffer ... "Top")) (if (string= start "BOTTOM") (py-find-next-exception ... buffer ... "Bottom") (py-find-next-exception ... buffer ... "Bottom")))
  (let* ((name ...) (buffer ...)) (when buffer (set-buffer ...)) (switch-to-buffer (current-buffer)) (if (eq direction ...) (if ... ... ...) (if ... ... ...)))
  py-find-next-exception-prepare(up nil)
  py-up-exception(nil)
  call-interactively(py-up-exception nil nil)

At this point the cursor in the *IPython* buffer is sitting at the start
of the "----> 1 demo1.f()" line. It's not much of a problem, because on
pressing C-c - again, the mini-buffer reports, "Top of traceback".

>> >> Secondly, the SyntaxError exceptions in the IPython buffer don't get
>> >> matched. Pressing C-c - does nothing with the following:
>> >>
>> >> In [1]: import demo2
>> >> File "demo3.py", line 4
>> >> if a != 25
>> >> ^
>> >> SyntaxError: invalid syntax
>> >>
Works well for me!

>> >> One thing that would be very useful would be to limit the searching for exception reporting lines to the *last* set of exceptions. If you have a long Python or IPython session there will probably be several exceptions and pressing C-c - repeatedly, not only goes up the stack for the last exception, but then revisits the stack for the previous one, and so on until the beginning of the buffer is reached. I don't know if it's feasible to narrow the search just to the last exception.
This too works well for me with Python, but with IPython presssing C-c -
repeatedly still goes back to previous stack traces. In case it helps,
I've attached the contents my *IPython* buffer that does this.

Thanks again.
Cheers,
Richard.

** Attachment added: "*IPython*"
   https://bugs.launchpad.net/bugs/913428/+attachment/2664701/+files/%2AIPython%2A

-- You received this bug notification because you are subscribed to the bug report. https://bugs.launchpad.net/bugs/913428 Title: py-down-exception IPython issues To manage notifications about this bug go to: https://bugs.launchpad.net/python-mode/+bug/913428/+subscriptions

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
milestone: none → 6.0.5
importance: Undecided → Medium
status: New → In Progress
Changed in python-mode:
status: In Progress → Fix Committed
Revision history for this message
Richard Everson (r-m-everson) wrote : Re: [Bug 913905] Re: py-up-exception remaining
Download full text (6.1 KiB)

Hi Andreas,

Sorry not to have got back to you sooner. The problem seems to be that with IPython the file is not listed as "<stdin>", but as, eg, "/Users/reverson/projects/edge/<ipython-input-2-1cebb13502c5> in <module>()", so the check in py-find-next-exception needs to check this. Here's a possible patch (against revno 772) which works for me -- I haven't checked the line number which the "<stdin>" check does.

ax:Emacs/el/python-mode/$ bzr log |head
------------------------------------------------------------
revno: 772
fixes bug(s): https://launchpad.net/bugs/913905
committer: Andreas Roehler <email address hidden>
branch nick: python-mode
timestamp: Tue 2012-01-10 13:48:47 +0100
message:
  `py-up-exception' again, lp:913905
------------------------------------------------------------
revno: 771
ax:Emacs/el/python-mode/$ bzr diff -p1
=== modified file 'python-mode.el'
--- old/python-mode.el 2012-01-10 12:48:47 +0000
+++ new/python-mode.el 2012-01-10 18:09:23 +0000
@@ -6110,7 +6110,8 @@
                   (setq file (substring file 0 -1)))
                 (when (string= errwhere "Bottom") (goto-char pos))
                 (if (and file line)
- (if (and (string= "<stdin>" file) (eq 1 line))
+ (if (or (and (string= "<stdin>" file) (eq 1 line))
+ (string-match "<ipython-input-" file))
                         (error "%s of traceback" errwhere)
                       (py-jump-to-exception file line py-line-number-offset))
                   (error "%s of traceback" errwhere)))

Best,
Richard.

On 10 Jan 2012, at 13:07, Andreas Roehler wrote:

> ** Changed in: python-mode
> Status: In Progress => Fix Committed
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/913905
>
> Title:
> py-up-exception remaining
>
> Status in An Emacs mode for editing Python code:
> Fix Committed
>
> Bug description:
> Hi Andreas,
>
> A good improvement. There's still a minor bug with IPython and moving
> up the stacks with C-c -. In the demo1.py example, pressing C-c -
> repeatedly goes up the stack until the
>
> ----> 1 demo1.f()
>
> line is reached, at which point string-match says "wrong-type-argument
> stringp nil"; here's the backtrace:
>
> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
> string-match(".+.pyc" nil)
> (if (string-match ".+.pyc" file) (progn (setq file ...)))
> (when (string-match ".+.pyc" file) (setq file (substring file 0 -1)))
> (progn (setq py-last-exeption-buffer (current-buffer)) (if (save-match-data ...) (progn ...) (setq line ... pos ... file ...)) (when (string-match ".+.pyc" file) (setq file ...)) (when (string= errwhere "Bottom") (goto-char pos)) (if (and file line) (if ... ... ...) (error "%s of traceback" errwhere)))
> (if (not (save-match-data ...)) (progn (setq py-last-exeption-buffer ...) (if ... ... ...) (when ... ...) (when ... ...) (if ... ... ...)) (goto-char orig) (error "%s of traceback" errwhere))
> (if (save-match-data (eq ... origline)) (progn (forward-line ...) (py-find-next-exception start buffer searchdir...

Read more...

Changed in python-mode:
status: Fix Committed → In Progress
Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 10.01.2012 19:20, schrieb Richard Everson:
> Hi Andreas,
>
> Sorry not to have got back to you sooner. The problem seems to be that
> with IPython the file is not listed as "<stdin>", but as, eg,
> "/Users/reverson/projects/edge/<ipython-input-2-1cebb13502c5> in
> <module>()", so the check in py-find-next-exception needs to check this.
> Here's a possible patch (against revno 772) which works for me -- I
> haven't checked the line number which the "<stdin>" check does.
>
>
> ax:Emacs/el/python-mode/$ bzr log |head
> ------------------------------------------------------------
> revno: 772
> fixes bug(s): https://launchpad.net/bugs/913905
> committer: Andreas Roehler<email address hidden>
> branch nick: python-mode
> timestamp: Tue 2012-01-10 13:48:47 +0100
> message:
> `py-up-exception' again, lp:913905
> ------------------------------------------------------------
> revno: 771
> ax:Emacs/el/python-mode/$ bzr diff -p1
> === modified file 'python-mode.el'
> --- old/python-mode.el 2012-01-10 12:48:47 +0000
> +++ new/python-mode.el 2012-01-10 18:09:23 +0000
> @@ -6110,7 +6110,8 @@
> (setq file (substring file 0 -1)))
> (when (string= errwhere "Bottom") (goto-char pos))
> (if (and file line)
> - (if (and (string= "<stdin>" file) (eq 1 line))
> + (if (or (and (string= "<stdin>" file) (eq 1 line))
> + (string-match "<ipython-input-" file))
> (error "%s of traceback" errwhere)
> (py-jump-to-exception file line py-line-number-offset))
> (error "%s of traceback" errwhere)))
>
>
> Best,
> Richard.
>

thanks, applied.

BTW there was a chunk which went only into the components branch last
commit - now present, aiming at the same.

cheers,

Andreas

>

Changed in python-mode:
status: In Progress → Fix Committed
Revision history for this message
Richard Everson (r-m-everson) wrote :
Download full text (5.2 KiB)

Hi Andreas,

Works pretty well for me. There's just one slight niggle -- sorry! If you use C-c - to go all the way to the top of the stack trace (in IPython), you can't use C-c = to come back down again unless you first move the cursor in the *IPython* buffer down a line from the "/Users/reverson/projects/edge/<ipython-input-2-1cebb13502c5> in <module>()" line --- pressing C-c = just gives a message "Bottom of traceback". This works fine with plain Python, but I can't see precisely what's causing it.

Sorry to keep on about it, but it is so useful to be able to traverse the stack in Emacs.

Cheers,
Richard.

PS: Am sending some more stuff about Pymacs in a separate email.

On 10 Jan 2012, at 21:14, Andreas Roehler wrote:

> ** Changed in: python-mode
> Status: In Progress => Fix Committed
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/913905
>
> Title:
> py-up-exception remaining
>
> Status in An Emacs mode for editing Python code:
> Fix Committed
>
> Bug description:
> Hi Andreas,
>
> A good improvement. There's still a minor bug with IPython and moving
> up the stacks with C-c -. In the demo1.py example, pressing C-c -
> repeatedly goes up the stack until the
>
> ----> 1 demo1.f()
>
> line is reached, at which point string-match says "wrong-type-argument
> stringp nil"; here's the backtrace:
>
> Debugger entered--Lisp error: (wrong-type-argument stringp nil)
> string-match(".+.pyc" nil)
> (if (string-match ".+.pyc" file) (progn (setq file ...)))
> (when (string-match ".+.pyc" file) (setq file (substring file 0 -1)))
> (progn (setq py-last-exeption-buffer (current-buffer)) (if (save-match-data ...) (progn ...) (setq line ... pos ... file ...)) (when (string-match ".+.pyc" file) (setq file ...)) (when (string= errwhere "Bottom") (goto-char pos)) (if (and file line) (if ... ... ...) (error "%s of traceback" errwhere)))
> (if (not (save-match-data ...)) (progn (setq py-last-exeption-buffer ...) (if ... ... ...) (when ... ...) (when ... ...) (if ... ... ...)) (goto-char orig) (error "%s of traceback" errwhere))
> (if (save-match-data (eq ... origline)) (progn (forward-line ...) (py-find-next-exception start buffer searchdir errwhere)) (if (not ...) (progn ... ... ... ... ...) (goto-char orig) (error "%s of traceback" errwhere)))
> (if (funcall searchdir py-traceback-line-re nil t) (if (save-match-data ...) (progn ... ...) (if ... ... ... ...)))
> (let ((orig ...) (origline ...) file line pos) (goto-char (py-point start)) (if (funcall searchdir py-traceback-line-re nil t) (if ... ... ...)))
> py-find-next-exception(bol "*IPython*" re-search-backward "Top")
> (if (string= start "TOP") (py-find-next-exception (quote bob) buffer (quote re-search-forward) "Top") (py-find-next-exception (quote bol) buffer (quote re-search-backward) "Top"))
> (if (eq direction (quote up)) (if (string= start "TOP") (py-find-next-exception ... buffer ... "Top") (py-find-next-exception ... buffer ... "Top")) (if (string= start "BOTTOM") (py-find-next-exception ... buffer ... "Bottom") (py-find-next-exception ... buffer ... "B...

Read more...

Revision history for this message
Andreas Roehler (a-roehler) wrote :

Am 11.01.2012 01:01, schrieb Richard Everson:
> Hi Andreas,
>
> Works pretty well for me. There's just one slight niggle -- sorry!

Hi Richard,

no need for sorry - on the contrary.
Your reports are very valuable, thanks a lot.

Please don't hesitate also sending feature requests, in which direction
to extend python-mode.

  If
> you use C-c - to go all the way to the top of the stack trace (in
> IPython), you can't use C-c = to come back down again unless you first
> move the cursor in the *IPython* buffer down a line from the
> "/Users/reverson/projects/edge/<ipython-input-2-1cebb13502c5> in
> <module>()" line --- pressing C-c = just gives a message "Bottom of
> traceback". This works fine with plain Python, but I can't see
> precisely what's causing it.
>
> Sorry to keep on about it, but it is so useful to be able to traverse
> the stack in Emacs.
>
> Cheers,
> Richard.
>
>
> PS: Am sending some more stuff about Pymacs in a separate email.
>
>

Got it, thanks.

It would be slightly more helpful though, if you could make a separate
report in all these cases - done for now. Well, that's a matter of
taste. Others may prefer a rather compound listing.

Cheers and thanks again,

Andreas

Changed in python-mode:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.