An Emacs mode for editing Python code

Bad handling of exceptions with py-execute-region

Reported by on 2013-03-23
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Andreas Roehler

Bug Description

I just installed python-mode.el-6.1.1 and I am seeing a pretty bad and unexpected handling of exceptions.

Let me show what I mean. Create an new Python code file called say "".
The only contents of this file will be this line:


Now open the interactive Python shell with 'M-x py-shell'. Mark this line in Emacs and then try to send this marked region to the Python interactive process using this Emacs command:

M-x py-execute-region

As you know, "5=6" is not a valid Python expression. What I normally expect when sending this to Python interpreter is to see the error message that's produced by Python. Instead, I see in the Emacs message buffer a message: "Jumping to exception in file /usr/tmp/ on line 5"

Moreover, the buffer that used to display the Python shell now opens the temporary file with contents:

#! /bin/env python3
 # -*- coding: utf-8 -*-
import os; os.chdir("/home/akopps/python/")


Now, I don't know if this was the intended behavior, but I think this is extremely unfriendly. Instead of seeing a Python interpreter error, I see the unexpected and totally uncalled for action of opening the temporary file that I personally never even created myself. After digging through python-mode.el, I find that I can suppress this behavior if I add to my .emacs file the following line:

(setq py-jump-on-exception nil)

Apparently, py-jump-on-exception is the variable that controls this behavior. The question is, why is it set by default to a value with such unfriendly behavior?

Ok, after setting it to 'nil', I still see another issue. Let's repeat the same experiment. Create an empty python file with 5=6 in it, then then mark it, and run "M-x py-execute-region", again. This time I see the expected Python error in the Python shell buffer. However, at the same time, I am seeing in the Emacs message buffer a message that looks like this:

"Wrote /usr/tmp/"

My question is, why is it displayed? Do I really need to see this? After digging though python-mode.el, I see I can suppress this if I replace the line that says:

(write-region (point-min) (point-max) file nil t nil 'ask)


(write-region (point-min) (point-max) file nil 0 nil 'ask)

Now, it's up to you to decide if this is a bug or feature. When I type an invalid expression into an interactive Python shell (started with "python -i"), I just see the Python error. With emacs and python-mode.el I see all sorts of distracting messages and actions.

Changed in python-mode:
assignee: nobody → Andreas Roehler (a-roehler)
importance: Undecided → Medium
milestone: none → 6.1.2

Am 23.03.2013 13:26, schrieb <email address hidden>:
> Public bug reported:

Checked in a fix. Please try again from trunk.



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

Other bug subscribers