Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #21649
| From | Robert Kern <robert.kern@gmail.com> |
|---|---|
| Subject | Re: Enchancement suggestion for argparse: intuit type from default |
| Date | 2012-03-15 10:06 +0000 |
| References | <87pqcefyka.fsf@benfinney.id.au> <20120315055908.GA8886@cskk.homeip.net> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.665.1331806024.3037.python-list@python.org> (permalink) |
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. 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? 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. -- Robert Kern "I have come to believe that the whole world is an enigma, a harmless enigma that is made terrible by our own mad attempt to interpret it as though it had an underlying truth." -- Umberto Eco
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Enchancement suggestion for argparse: intuit type from default roy@panix.com (Roy Smith) - 2012-03-13 17:08 -0400
Re: Enchancement suggestion for argparse: intuit type from default Ben Finney <ben+python@benfinney.id.au> - 2012-03-14 08:35 +1100
Re: Enchancement suggestion for argparse: intuit type from default Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-03-14 12:53 +0000
Re: Enchancement suggestion for argparse: intuit type from default Ben Finney <ben+python@benfinney.id.au> - 2012-03-15 00:19 +1100
Re: Enchancement suggestion for argparse: intuit type from default Roy Smith <roy@panix.com> - 2012-03-14 09:30 -0400
Re: Enchancement suggestion for argparse: intuit type from default MRAB <python@mrabarnett.plus.com> - 2012-03-14 17:26 +0000
Re: Enchancement suggestion for argparse: intuit type from default Ian Kelly <ian.g.kelly@gmail.com> - 2012-03-14 13:03 -0600
Re: Enchancement suggestion for argparse: intuit type from default rusi <rustompmody@gmail.com> - 2012-03-14 03:22 -0700
Re: Enchancement suggestion for argparse: intuit type from default Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2012-03-14 13:26 +0100
Re: Enchancement suggestion for argparse: intuit type from default John Nagle <nagle@animats.com> - 2012-03-14 16:32 -0700
Re: Enchancement suggestion for argparse: intuit type from default Roy Smith <roy@panix.com> - 2012-03-14 20:52 -0400
Re: Enchancement suggestion for argparse: intuit type from default Ben Finney <ben+python@benfinney.id.au> - 2012-03-15 12:22 +1100
Re: Enchancement suggestion for argparse: intuit type from default Cameron Simpson <cs@zip.com.au> - 2012-03-15 16:59 +1100
Re: Enchancement suggestion for argparse: intuit type from default Robert Kern <robert.kern@gmail.com> - 2012-03-15 10:06 +0000
Re: Enchancement suggestion for argparse: intuit type from default Roy Smith <roy@panix.com> - 2012-03-15 09:28 -0400
Re: Enchancement suggestion for argparse: intuit type from default Cameron Simpson <cs@zip.com.au> - 2012-03-16 08:18 +1100
Re: Enchancement suggestion for argparse: intuit type from default MRAB <python@mrabarnett.plus.com> - 2012-03-15 02:10 +0000
csiph-web