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: optparse: bad exception handling when giving no value to an option requiring one
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Gwendal.LE.BIHAN, r.david.murray
Priority: normal Keywords:

Created on 2010-08-10 21:25 by Gwendal.LE.BIHAN, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (4)
msg113560 - (view) Author: Gwendal LE BIHAN (Gwendal.LE.BIHAN) Date: 2010-08-10 21:25
Having created the parser this way:

optparser=OptionParser()
optparser.add_option("--share-dir",dest="share_dir",default="/usr/share")
options,args=optparser.parse_args()

And calling the program this way:

appname --share-dir

I get the following exception, which is not caught:

options,args=optparser.parse_args()
  File "/usr/lib/python2.6/optparse.py", line 1394, in parse_args
    stop = self._process_args(largs, rargs, values)
  File "/usr/lib/python2.6/optparse.py", line 1434, in _process_args
    self._process_long_opt(rargs, values)
  File "/usr/lib/python2.6/optparse.py", line 1509, in _process_long_opt
    option.process(opt, value, values, self)
UnboundLocalError: local variable 'value' referenced before assignment
msg113568 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-10 23:08
2.6 no longer receives bug fixes now that 2.7 is out.  Is this still a problem in 2.7?  (My testing indicates that it isn't.)
msg113571 - (view) Author: Gwendal LE BIHAN (Gwendal.LE.BIHAN) Date: 2010-08-10 23:36
I confirm. Fixed in Python 2.7.
I didn't have Python 2.7 installed since it's not in the Ubuntu repository yet.
msg113576 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2010-08-11 01:14
Thanks for the confirmation.
History
Date User Action Args
2022-04-11 14:57:05adminsetgithub: 53772
2010-08-11 01:14:56r.david.murraysetstatus: open -> closed
resolution: out of date
messages: + msg113576

stage: test needed -> resolved
2010-08-10 23:36:16Gwendal.LE.BIHANsetmessages: + msg113571
2010-08-10 23:08:05r.david.murraysetnosy: + r.david.murray

messages: + msg113568
stage: test needed
2010-08-10 21:26:13Gwendal.LE.BIHANsettitle: bad exception handling when giving no value to an option requiring one -> optparse: bad exception handling when giving no value to an option requiring one
2010-08-10 21:25:27Gwendal.LE.BIHANcreate