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


Groups > comp.lang.python > #21649

Re: Enchancement suggestion for argparse: intuit type from default

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.016
X-Spam-Evidence '*H*': 0.97; '*S*': 0.00; 'indicates': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'underlying': 0.09; 'am,': 0.12; 'argparse': 0.16; 'enigma': 0.16; 'finney': 0.16; 'intuition': 0.16; 'kern': 0.16; 'roy': 0.16; 'subject:argparse': 0.16; 'wrote:': 0.18; 'that?': 0.18; 'seems': 0.20; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'string': 0.24; 'writes:': 0.25; 'code': 0.26; 'function': 0.27; 'value.': 0.28; 'interpret': 0.29; 'admit': 0.30; 'none,': 0.30; 'object.': 0.30; 'yes.': 0.30; 'that,': 0.32; 'header:User-Agent:1': 0.33; 'too': 0.33; 'object': 0.33; 'match': 0.34; 'header:X-Complaints- To:1': 0.34; 'then.': 0.34; 'problem.': 0.35; 'probably': 0.35; 'to:addr:python-list': 0.35; 'received:org': 0.36; 'saves': 0.37; 'but': 0.37; "i'll": 0.38; 'cases,': 0.38; 'could': 0.38; 'should': 0.38; 'option': 0.39; 'unless': 0.39; 'subject:from': 0.39; 'called': 0.40; 'to:addr:python.org': 0.40; 'easy': 0.60; 'type': 0.61; 'simple': 0.61; 'world': 0.61; 'received:86': 0.63; 'our': 0.63; 'believe': 0.65; 'special': 0.66; 'designed': 0.69; 'cameron': 0.77; 'eco': 0.91
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Robert Kern <robert.kern@gmail.com>
Subject Re: Enchancement suggestion for argparse: intuit type from default
Date Thu, 15 Mar 2012 10:06:48 +0000
References <87pqcefyka.fsf@benfinney.id.au> <20120315055908.GA8886@cskk.homeip.net>
Mime-Version 1.0
Content-Type text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host host86-147-15-181.range86-147.btcentralplus.com
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.7; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2
In-Reply-To <20120315055908.GA8886@cskk.homeip.net>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.665.1331806024.3037.python-list@python.org> (permalink)
Lines 31
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1331806024 news.xs4all.nl 6906 [2001:888:2000:d::a6]:44814
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21649

Show key headers only | View raw


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 | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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