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.

classification
Title: IDLE and except: raise from
Type: behavior Stage: resolved
Components: IDLE Versions: Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: serhiy.storchaka Nosy List: Jocjo, Ramchandra Apte, ezio.melotti, loewis, mark.dickinson, python-dev, roger.serwy, serhiy.storchaka, terry.reedy
Priority: normal Keywords: patch

Created on 2012-11-17 08:32 by Jocjo, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Hans.vcf Jocjo, 2012-11-17 08:32
try-execpt-raise-bug.rtf Jocjo, 2012-11-17 08:32
idle_print_exception.patch serhiy.storchaka, 2012-11-24 11:05 Patch for 3.3+ review
idle_print_exception-3.2.patch serhiy.storchaka, 2012-11-24 11:05 Patch for 3.2 review
Messages (14)
msg175728 - (view) Author: Hans Larsen (Jocjo) Date: 2012-11-17 08:32
Med venlig hilsen:
Hans Larsen
Galgebakken Sønder 4-11A
DK-2620 Albertslund
Danmark/Danio
I has found a bug in Python3.3 on Windows!
Why are all 3 try-statements equal?
I don’t see a “..During handling of above exception, another exception occured: ...”
Where is the bug!
I use Windows 7 64bit!
msg175729 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-11-17 08:45
Please could you give a coherent description of the behaviour you think is a bug.  Include:  (1) what you did, (2) what results you got (including tracebacks for exceptions), (3) what results you expected to get.
msg175730 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2012-11-17 09:34
Here's the contents of the .rtf file:

PythonWin 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32.
Portions Copyright 1994-2008 Mark Hammond - see 'Help/About PythonWin' for further copyright information.
try:
... 	1/0
... except ZeroDivisionError as exp:
... 	raise TypeError('Divided by 0')
... 
Traceback (most recent call last):
  File "<interactive input>", line 4, in <module>
TypeError: Divided by 0
try:
... 	1/0
... except ZeroDivisionError as exp:
... 	raise TypeError('Divided by 0') from exp
... 
Traceback (most recent call last):
  File "<interactive input>", line 4, in <module>
TypeError: Divided by 0
try:
... 	1/0
... except ZeroDivisionError:
... 	raise TypeError('Divided by 0') from None
... 
Traceback (most recent call last):
  File "<interactive input>", line 4, in <module>
TypeError: Divided by 0
msg175736 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2012-11-17 13:40
Also, please report bugs in English.
(read the devguide to learn more)
msg175737 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2012-11-17 13:45
That looks like a bug/missing feature in PythonWin to me, which doesn't print __context__ properly. Note: I haven't tested PythonWin to confirm.

Hans: is the output also incorrect in IDLE, or a command line shell? If no, then this isn't a bug in Python itself, but one in PythonWin. You can find the bug tracker at 

http://sourceforge.net/projects/pywin32/

Ramchandra: the bug report actually *is* in English, starting with "I has found ...". The first part is just Hans' postal address (which we don't really need here, but it doesn't hurt having it, either).
msg176038 - (view) Author: Hans Larsen (Jocjo) Date: 2012-11-20 23:41
-----Oprindelig meddelelse----- 
From: Martin v. Löwis
Sent: Saturday, November 17, 2012 2:45 PM
To: jocjo@mail.dk
Subject: [issue16491] try-except-raise-bug

Martin v. Löwis added the comment:

That looks like a bug/missing feature in PythonWin to me, which doesn't 
print __context__ properly. Note: I haven't tested PythonWin to confirm.

Hans: is the output also incorrect in IDLE, or a command line shell? If no, 
then this isn't a bug in Python itself, but one in PythonWin. You can find 
the bug tracker at

http://sourceforge.net/projects/pywin32/

Ramchandra: the bug report actually *is* in English, starting with "I has 
found ...". The first part is just Hans' postal address (which we don't 
really need here, but it doesn't hurt having it, either).

I have tried it in Python IDLE, but it's the samme except that returns a 
TypeError instead!
----------
nosy: +loewis

_______________________________________
Python tracker <report@bugs.python.org>
<http://bugs.python.org/issue16491>
_______________________________________
msg176165 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-23 12:38
Can you paste the traceback you get with IDLE and also try the same from the command line?
msg176227 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2012-11-23 19:54
I marked this as 3.3+ bug because double reporting is new in 3.x and 'from None' is new in 3.3 (it causes a TypeError in the raise statement ;-).

Command prompt output appears 'correct' (as intended).
[I added blank lines before each try: for reading ease]

Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17)
 [MSC v.1600 64 bit (AMD64)] on win32

>>> try:
...     1/0
... except ZeroDivisionError as exp:
...     raise TypeError('Divided by 0')
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
TypeError: Divided by 0

>>> try:
...     1/0
... except ZeroDivisionError as exp:
...     raise TypeError('Divided by 0') from exp
...
Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
ZeroDivisionError: division by zero

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
TypeError: Divided by 0

>>> try:
...     1/0
... except ZeroDivisionError as exp:
...     raise TypeError('Divided by 0') from None
...
Traceback (most recent call last):
  File "<stdin>", line 4, in <module>
TypeError: Divided by 0

---------------------------------------------------
In IDLE on Win 7 64, all three give
Traceback (most recent call last):
  File "F:\Python\mypy\tem.py", line 4, in <module>
    raise TypeError('Divided by 0')  # except for change here
TypeError: Divided by 0

We need to see non-Windows IDLE output to see if problem is limited to running with pythonw. Here is copy-paste code.

try:
    1/0
except ZeroDivisionError as exp:
    raise TypeError('Divided by 0') from None
msg176231 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-23 20:05
On Linux the result is the same.
msg176267 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-24 08:11
The bug is somewhere in print_exception() function in Lib/idlelib/run.py.
msg176280 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-24 11:05
Here is a patch.
msg178327 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-27 20:53
If no one objects I will commit this next year.
msg179430 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-01-09 10:29
New changeset f28aff31900a by Serhiy Storchaka in branch '3.2':
Issue #16491: IDLE now prints chained exception tracebacks.
http://hg.python.org/cpython/rev/f28aff31900a

New changeset 3feead75c7a5 by Serhiy Storchaka in branch '3.3':
Issue #16491: IDLE now prints chained exception tracebacks.
http://hg.python.org/cpython/rev/3feead75c7a5

New changeset 0793d68a0eba by Serhiy Storchaka in branch 'default':
Issue #16491: IDLE now prints chained exception tracebacks.
http://hg.python.org/cpython/rev/0793d68a0eba
msg179431 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2013-01-09 10:36
Fixed. Thank you for report, Hans.
History
Date User Action Args
2022-04-11 14:57:38adminsetgithub: 60695
2013-01-09 10:36:34serhiy.storchakasetstatus: open -> closed
messages: + msg179431

components: + IDLE
resolution: fixed
stage: patch review -> resolved
2013-01-09 10:29:25python-devsetnosy: + python-dev
messages: + msg179430
2012-12-27 20:53:34serhiy.storchakasetassignee: serhiy.storchaka
messages: + msg178327
2012-11-24 11:06:29serhiy.storchakasetstage: needs patch -> patch review
2012-11-24 11:05:58serhiy.storchakasetfiles: + idle_print_exception-3.2.patch
versions: + Python 3.2
2012-11-24 11:05:19serhiy.storchakasetfiles: + idle_print_exception.patch
keywords: + patch
messages: + msg176280
2012-11-24 08:11:09serhiy.storchakasetmessages: + msg176267
2012-11-23 20:05:42serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg176231
2012-11-23 19:54:11terry.reedysetnosy: + roger.serwy, terry.reedy
title: try-except-raise-bug -> IDLE and except: raise from
messages: + msg176227

versions: + Python 3.3, Python 3.4
stage: needs patch
2012-11-23 12:38:16ezio.melottisettype: behavior
messages: + msg176165
2012-11-20 23:41:12Jocjosetstatus: pending -> open

messages: + msg176038
2012-11-19 15:38:40ezio.melottisetstatus: open -> pending
nosy: + ezio.melotti
2012-11-17 13:45:07loewissetnosy: + loewis
messages: + msg175737
2012-11-17 13:40:35Ramchandra Aptesetnosy: + Ramchandra Apte
messages: + msg175736
2012-11-17 09:34:03mark.dickinsonsetmessages: + msg175730
2012-11-17 08:45:08mark.dickinsonsetnosy: + mark.dickinson
messages: + msg175729
2012-11-17 08:32:23Jocjocreate