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: 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 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On 3/15/12 5:59 AM, Cameron Simpson wrote: > On 15Mar2012 12:22, Ben Finney wrote: > | Roy Smith 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