Uploaded image for project: 'Data Management'
  1. Data Management
  2. DM-9433

ds9.py error code not working as intended

    Details

    • Type: Bug
    • Status: Done
    • Resolution: Done
    • Fix Version/s: None
    • Component/s: afw
    • Story Points:
      0.5
    • Epic Link:
    • Sprint:
      Alert Production S17 - 2
    • Team:
      Alert Production

      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 <module>
          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.

        Attachments

          Issue Links

            Activity

            Hide
            tjenness Tim Jenness added a comment -

            This fix is acceptable to me.

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

            See my comment on the pull request

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

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

            Show
            rowen Russell Owen added a comment - I think I'd rather make the binding explicit. That should be easy enough.
            Hide
            tjenness 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
            tjenness 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:
                rowen Russell Owen
                Reporter:
                rowen Russell Owen
                Reviewers:
                Tim Jenness
                Watchers:
                Russell Owen, Tim Jenness
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Summary Panel