Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed5.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.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'defaults': 0.07; 'foo': 0.09; 'str,': 0.09; 'am,': 0.12; 'argument': 0.15; 'case.': 0.15; '7:30': 0.16; 'roy': 0.16; 'subject:argparse': 0.16; '\xa0what': 0.16; 'cc:addr:python-list': 0.16; 'wed,': 0.17; 'wrote:': 0.18; 'seems': 0.20; 'cheers,': 0.20; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'int,': 0.23; '\xa0if': 0.23; 'ignore': 0.24; 'string': 0.24; 'cc:2**0': 0.26; 'value.': 0.28; "i'm": 0.28; 'message- id:@mail.gmail.com': 0.29; 'interact': 0.29; 'cc:addr:python.org': 0.29; 'user.': 0.31; 'cases': 0.32; 'list': 0.32; 'there': 0.33; 'be,': 0.34; 'integer': 0.34; 'probably': 0.35; 'list.': 0.35; 'run': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'should': 0.38; 'clearly': 0.39; 'that.': 0.39; 'subject:from': 0.39; 'received:209': 0.39; 'might': 0.40; 'type': 0.61; 'custom': 0.61; 'here': 0.64; 'have?': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=mZKaa0vhhyosJlAQ9uClRG6hqMJcsn/GyzeZY8JnXJE=; b=T/L91ahawEf7/XwDWw+iYPppIm0VyjJe0cBrjjTAaIbsnDvUBSsPKFeU2V6QfkMDzm skM/35GVLZvYsUodhTWRd/vuQTYlYKpC3Fy0ADVGUNYny/8WKmFHlb00jFxnVe6HzqiB pbSsp6j2kbngiawN4EOhodVz5bdzoaCYGPYtCuKNPlgJ+bjQBIwff0dXMbxsgmOV2V5L VTFz0kWUnC4BJeUcZoO7ZNPEWu6pr9oAQBuPyCiQc5/5VhVBImRi7kpNhDkNfHAxXVDv YCOCAwAyZD2wr9n0QHv5nLRoBIKVuhfwAc053cf4ADr+3MXPCufYTH53i6OIym7wZxbr Jf5A== MIME-Version: 1.0 In-Reply-To: References: <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <87399bgw18.fsf@benfinney.id.au> From: Ian Kelly Date: Wed, 14 Mar 2012 13:03:28 -0600 Subject: Re: Enchancement suggestion for argparse: intuit type from default To: Roy Smith Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org 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: 45 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1331751840 news.xs4all.nl 6883 [2001:888:2000:d::a6]:47773 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:21622 On Wed, Mar 14, 2012 at 7:30 AM, Roy Smith wrote: > It's already inferred that the type is a string if you don't give it any > value. =A0What possible meaning could: > > parser.add_argument('--foo', default=3D100) > > have? =A0If I run the program with: > > $ prog > > then foo defaults to the integer 100, but if I run it with: > > $ prog --foo=3D100 > > then I get the string "100"? =A0Surely there's not much of a use case for > that. What about: parser.add_argument('--foo', default=3DNone) Probably it should not infer NoneType as the argument type in this case. So would it just ignore the default in this case and let the type remain str? Also, how would the inference interact with different actions? For example= : parser.add_argument('--foo', action=3D'append', default=3D['one']) I'm not exactly sure what a use case for this might be, but anyway, the type here should clearly be str, not list. And then what about this variation: parser.add_argument('--foo', action=3D'append', default=3D[1]) Should it try to infer that because the list contains an int, the type should be int? And even if you manage to get the inference working flawlessly and expectedly for append, what about custom actions? It seems to me that there are a large number of edge cases here that will end up hurting predictability for the end user. Cheers, Ian