Enchancement suggestion for argparse: intuit type from default

Cameron Simpson cs at zip.com.au
Thu Mar 15 11:35:03 CET 2012


On 15Mar2012 10:06, Robert Kern <robert.kern at gmail.com> wrote:
| On 3/15/12 5:59 AM, Cameron Simpson wrote:
| > On 15Mar2012 12:22, Ben Finney<ben+python at benfinney.id.au>  wrote:
| > | Roy Smith<roy at panix.com>  writes:
| > |>  I'll admit I hadn't considered that, but I don't see it as a major
| > |>  problem. The type intuition could be designed to only work for types
| > |>  other than NoneType.
| > |
| > | −1, then. It's growing too many special cases, and is no longer simple
| > | to describe, so that indicates it's probably a bad idea.
| >
| > If `type` is not supplied and `default` is present and not None, `type`
| > shall be the type of `default`.
| >
| > That seems straightforward to me. [... sentinels aside...] the `type`
| > should always match type(default). Or am I wrong about that?
| 
| Yes. Not all type(default) types can be called with a string to produce a valid 
| value. Note that "type=" is really a misnomer. argparse doesn't really want a 
| type object there; it wants a converter function that takes a string to an object.

Aha. Still, you could change the docs to say you only need type= if
type(default) _isn't_ useful as the string->value converter.
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

As your attorney, it is my duty to inform you that it is not important that
you understand what I'm doing or why you're paying me so much money. What's
important is that you continue to do so.
        - Hunter S. Thompson's Samoan Attorney



More information about the Python-list mailing list