Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optparse: bad exception handling when giving no value to an option requiring one #53772

Closed
GwendalLEBIHAN mannequin opened this issue Aug 10, 2010 · 4 comments
Closed
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@GwendalLEBIHAN
Copy link
Mannequin

GwendalLEBIHAN mannequin commented Aug 10, 2010

BPO 9563
Nosy @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2010-08-11.01:14:56.805>
created_at = <Date 2010-08-10.21:25:27.074>
labels = ['type-bug', 'library']
title = 'optparse: bad exception handling when giving no value to an option requiring one'
updated_at = <Date 2010-08-11.01:14:56.804>
user = 'https://bugs.python.org/GwendalLEBIHAN'

bugs.python.org fields:

activity = <Date 2010-08-11.01:14:56.804>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2010-08-11.01:14:56.805>
closer = 'r.david.murray'
components = ['Library (Lib)']
creation = <Date 2010-08-10.21:25:27.074>
creator = 'Gwendal.LE.BIHAN'
dependencies = []
files = []
hgrepos = []
issue_num = 9563
keywords = []
message_count = 4.0
messages = ['113560', '113568', '113571', '113576']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'Gwendal.LE.BIHAN']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue9563'
versions = ['Python 2.6']

@GwendalLEBIHAN
Copy link
Mannequin Author

GwendalLEBIHAN mannequin commented Aug 10, 2010

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

@GwendalLEBIHAN GwendalLEBIHAN mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Aug 10, 2010
@GwendalLEBIHAN GwendalLEBIHAN mannequin changed the title 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 Aug 10, 2010
@bitdancer
Copy link
Member

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

@GwendalLEBIHAN
Copy link
Mannequin Author

GwendalLEBIHAN mannequin commented Aug 10, 2010

I confirm. Fixed in Python 2.7.
I didn't have Python 2.7 installed since it's not in the Ubuntu repository yet.

@bitdancer
Copy link
Member

Thanks for the confirmation.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant