Enchancement suggestion for argparse: intuit type from default

Cameron Simpson cs at zip.com.au
Thu Mar 15 06:59:08 CET 2012


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. It's a single sentence, easy to read
and understand, and potentially saves a lot of code verbiage (gratuitous
type= prarameters). I say "gratuitous" because unless `default` is a
sentinel for "no option supplied", the `type` should always match
type(default). Or am I wrong about that?

Cheers,
-- 
Cameron Simpson <cs at zip.com.au> DoD#743
http://www.cskk.ezoshosting.com/cs/

You only live once in life, but if you do it right, once is enough!
        - Rob Castro <rdc8 at columbia.edu>



More information about the Python-list mailing list