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.

Author krichter
Recipients krichter
Date 2014-04-12.21:58:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1397339884.4.0.416428545862.issue21208@psf.upfronthosting.co.za>
In-reply-to
Content
As arguments with type bool are the only ones whose values can be manipulated without passing an option to the argument on CLI, the default behavior for those should be changed from ignoring options to failing when options are specified. Consider the following example:
<code>

import argparse

cache_size_default=1000
cache_size_option = "c"
cache_size_option_long = "cache-size"
start_db_default = False
start_db_option = "t"
start_db_option_long = "start-db"


parser = argparse.ArgumentParser(description='Process some integers.')               
parser.add_argument("-%s" % start_db_option, "--%s" % start_db_option_long, default=start_db_default, type=bool, nargs='?',
                   help='@TODO', dest=start_db_option_long)
parser.add_argument("-%s" % cache_size_option, "--%s" % cache_size_option_long, type=int, nargs='?', default=cache_size_default, 
                   help='size of osm2pgsql cache', dest=cache_size_option_long)

def osm_postgis_transform(cache_size=cache_size_default, start_db=start_db_default):
    print(start_db, cache_size)

if __name__ == "__main__":
    args = vars(parser.parse_args())
    osm_postgis_transform(cache_size=args[cache_size_option_long], start_db=args[start_db_option_long])
</code>

When the script is invoked with 
<code>
python issue-argparse.py --start-db False --cache-size 2000
</code>
The value for start-db is True which is not really intuitive. Changing the default behavior to either fail at argument parsing or overwrite the argument value would be an improvement in my opinion.
History
Date User Action Args
2014-04-12 21:58:04krichtersetrecipients: + krichter
2014-04-12 21:58:04krichtersetmessageid: <1397339884.4.0.416428545862.issue21208@psf.upfronthosting.co.za>
2014-04-12 21:58:04krichterlinkissue21208 messages
2014-04-12 21:58:03krichtercreate