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 "append" action should always make the em
Type: enhancement Stage:
Components: None Versions:
process
Status: closed Resolution: rejected
Dependencies: Superseder:
Assigned To: gward Nosy List: fdrake, gward, jemfinch
Priority: normal Keywords:

Created on 2003-10-07 10:47 by jemfinch, last changed 2022-04-10 16:11 by admin. This issue is now closed.

Messages (4)
msg54046 - (view) Author: Jeremy Fincher (jemfinch) Date: 2003-10-07 10:47
I was torn between "Bug" and "RFE" on this one.

Anyway, with options whose action is "append",
optparse.OptionParser will set the option to None if
it's never called.  Instead, I think it should set the
option to the empty list, so code can iterate over the
list regardless of whether the option was ever given. 
It keeps users from having to guard their iteration
with "if options.foo:"

Such a change would be slightly backwards-incompatible;
users who use "if option.foo is None:" form instead of
just "if not options.foo:" would run into trouble, as
well as those users who used an "else" statement in
their loops.  The latter seemed like a big problem,
until I realized that those users' code *already*
guards against the empty case, and thus shouldn't run
into difficulties.
msg54047 - (view) Author: Jeremy Fincher (jemfinch) Date: 2003-10-07 10:48
Logged In: YES 
user_id=99508

So, I *thought* I could change this to an RFE after
submitting it, but apparently not.
msg54048 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2004-04-01 08:16
Logged In: YES 
user_id=3066

I'd agree that supplying [] as the default is the right
thing to do, but the compatibility issue pretty much kills
it.  This should probably become a documentation issue; a
hint to use default=[] would go a long way, and works with
the existing code.
msg54049 - (view) Author: Greg Ward (gward) (Python committer) Date: 2004-05-05 01:42
Logged In: YES 
user_id=14422

First of all, this should have been filed with the 'optik'
project, not Python.  Oh well, no matter, because I'm going
to refuse it anyways.
Adding "default=[]" to the add_option() call is not such a
burden, and
Optik/optparse is mature enough that I don't want to break b/w
compatibility.
History
Date User Action Args
2022-04-10 16:11:39adminsetgithub: 39381
2003-10-07 10:47:00jemfinchcreate