Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #21650

Re: Enchancement suggestion for argparse: intuit type from default

Date 2012-03-15 21:35 +1100
From Cameron Simpson <cs@zip.com.au>
Subject Re: Enchancement suggestion for argparse: intuit type from default
References <jjsevn$nsn$1@dough.gmane.org>
Newsgroups comp.lang.python
Message-ID <mailman.666.1331807597.3037.python-list@python.org> (permalink)

Show all headers | View raw


On 15Mar2012 10:06, Robert Kern <robert.kern@gmail.com> wrote:
| On 3/15/12 5:59 AM, Cameron Simpson wrote:
| > On 15Mar2012 12:22, Ben Finney<ben+python@benfinney.id.au>  wrote:
| > | Roy Smith<roy@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@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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Enchancement suggestion for argparse: intuit type from default Cameron Simpson <cs@zip.com.au> - 2012-03-15 21:35 +1100

csiph-web