classification
Title: wrong error from curses.wrapper if curses initialization fails
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: ned.deily Nosy List: akuchling, macfreek, ned.deily, python-dev
Priority: normal Keywords: easy, patch

Created on 2009-03-31 15:00 by ned.deily, last changed 2011-03-09 10:53 by ned.deily. This issue is now closed.

Files
File name Uploaded Description Edit
patch-nad0018.txt ned.deily, 2009-03-31 15:00
Messages (7)
msg84793 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2009-03-31 15:00
wrong error from curses.wrapper if curses initialization fails

One way to reproduce is trying under IDLE.app in OS X:

  import curses
  def scr(a):
    a.getch()

  curses.wrapper(scr)

Traceback before patch:
  UnboundLocalError: local variable 'stdscr' referenced before 
assignment

Traceback after patch:
  _curses.error: setupterm: could not find terminal

APPLIES         2.6, 2.7, 3.0, 3.1
msg112159 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2010-07-31 15:46
This is a one line patch on wrapper.py.  Sorry I can't do any more with this cos I only have a windows box.
msg112161 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2010-07-31 15:52
[FYI: Comments at the beginning of a patch file are ignored by the standard Unix-y patch utilities.  They are there for a reason.]
msg114043 - (view) Author: Freek Dijkstra (macfreek) Date: 2010-08-16 13:20
I can confirm that both the problem exists and the patch works on Python 2.6 and 3.1. I love to see it committed.
msg125812 - (view) Author: Ned Deily (ned.deily) * (Python committer) Date: 2011-01-09 00:07
A simpler way to reproduce:
TERM= python -c 'import curses; curses.wrapper(lambda a:a.getch())'

I looked at adding an automated test case for this but it is a little tricky to make it bulletproof across all environments. Since the problem is really a one-time coding error, perhaps a permanent test case can be omitted?
msg130439 - (view) Author: Roundup Robot (python-dev) Date: 2011-03-09 10:33
New changeset c731e02472c5 by Ned Deily in branch '2.7':
Issue #5622: Fix curses.wrapper to raise correct exception if curses
http://hg.python.org/cpython/rev/c731e02472c5
msg130444 - (view) Author: Roundup Robot (python-dev) Date: 2011-03-09 10:50
New changeset 6b6b8af33811 by Ned Deily in branch '3.1':
Issue #5622: Fix curses.wrapper to raise correct exception if curses
http://hg.python.org/cpython/rev/6b6b8af33811

New changeset e6c45cd46cb2 by Ned Deily in branch '3.2':
Issue #5622: merge fix from 3.1.
http://hg.python.org/cpython/rev/e6c45cd46cb2

New changeset ec717db610df by Ned Deily in branch 'default':
Issue #5622: merge fix from 3.2.
http://hg.python.org/cpython/rev/ec717db610df
History
Date User Action Args
2011-03-09 10:53:21ned.deilysetstatus: open -> closed
assignee: ned.deily
resolution: fixed
nosy: akuchling, macfreek, ned.deily, python-dev
stage: patch review -> resolved
2011-03-09 10:50:45python-devsetnosy: akuchling, macfreek, ned.deily, python-dev
messages: + msg130444
2011-03-09 10:33:57python-devsetnosy: + python-dev
messages: + msg130439
2011-01-09 00:07:52ned.deilysetmessages: + msg125812
2010-11-21 06:59:18ned.deilysetfiles: - issue5622.diff
2010-11-21 06:59:11ned.deilysetkeywords: + easy
nosy: - BreamoreBoy
stage: test needed -> patch review

versions: - Python 2.6
2010-08-16 13:20:47macfreeksetnosy: + macfreek
messages: + msg114043
2010-07-31 15:58:29ned.deilysetnosy: + akuchling
2010-07-31 15:52:46ned.deilysetmessages: + msg112161
2010-07-31 15:46:08BreamoreBoysetfiles: + issue5622.diff

type: behavior
versions: + Python 3.2, - Python 3.0
keywords: + patch
nosy: + BreamoreBoy

messages: + msg112159
stage: test needed
2009-03-31 15:00:35ned.deilycreate