# ds9.py error code not working as intended

XMLWordPrintable

## Details

• Type: Bug
• Status: Done
• Resolution: Done
• Fix Version/s: None
• Component/s:
• Labels:
• Story Points:
0.5
• Sprint:
• Team:

## Description

The following code in afw's display/ds9.py appears to not function as intended:

  except Exception as e:  # No usable version of display_ds9.  # Let's define a version of getDisplay() which will throw an exception.  e.args = ["%s (is display_ds9 setup?)" % e]    def getDisplay(*args, **kwargs):  raise e    class DisplayImpl(object):  def __init__(self, *args, **kwargs):  raise e 

To see this run examples/estimateBackground.py with display_ds9 not set up. What I see is:

 Traceback (most recent call last):  File "examples/estimateBackground.py", line 109, in   main()  File "examples/estimateBackground.py", line 89, in main  ds9.mtv(image, frame=0)  File "/Users/rowen/UW/LSST/lsstsw3/build/afw/python/lsst/afw/display/ds9.py", line 84, in mtv  return getDisplay(frame, create=True).mtv(data, title, wcs, *args, **kwargs)  File "/Users/rowen/UW/LSST/lsstsw3/build/afw/python/lsst/afw/display/ds9.py", line 46, in getDisplay  raise e NameError: name 'e' is not defined 

I confess to some surprise. I am not an expert on Python's binding rules, but I expected the code to work.

## Activity

Hide
Tim Jenness added a comment -

This fix is acceptable to me.

Show
Tim Jenness added a comment - This fix is acceptable to me.
Hide
Russell Owen added a comment -

See my comment on the pull request

Show
Russell Owen added a comment - See my comment on the pull request
Hide
Russell Owen added a comment -

I think I'd rather make the binding explicit. That should be easy enough.

Show
Russell Owen added a comment - I think I'd rather make the binding explicit. That should be easy enough.
Hide
Tim Jenness added a comment -

This is a Python 2 vs 3 issue. The problem is that in Python 2 the e variable from the catch block persists even when the exception has been handled. In Python 3 the scope of as e is such that it's transient. If you copy the exception variable into a different variable in the line above e.args everything works on python 2 and 3.

Show
Tim Jenness added a comment - This is a Python 2 vs 3 issue. The problem is that in Python 2 the e variable from the catch block persists even when the exception has been handled. In Python 3 the scope of as e is such that it's transient. If you copy the exception variable into a different variable in the line above e.args everything works on python 2 and 3.

## People

• Assignee:
Russell Owen
Reporter:
Russell Owen
Reviewers:
Tim Jenness
Watchers:
Russell Owen, Tim Jenness
0 Vote for this issue
Watchers:
2 Start watching this issue

## Dates

• Created:
Updated:
Resolved: