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


Groups > comp.lang.python > #21613

Re: Enchancement suggestion for argparse: intuit type from default

Path csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!eweka.nl!feeder3.eweka.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <python@mrabarnett.plus.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.01; 'run- time': 0.05; 'defaults': 0.07; 'dislike': 0.07; 'suggesting': 0.07; 'type,': 0.07; 'declarations': 0.09; 'default.': 0.09; 'foo': 0.09; 'from:addr:python': 0.09; 'programmer': 0.10; 'argument': 0.15; 'argparse': 0.16; 'finney': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:name:mrab': 0.16; 'input.': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:84.92': 0.16; 'received:84.92.122': 0.16; 'received:84.92.122.60': 0.16; 'reply-to:addr:python-list': 0.16; 'roy': 0.16; 'subject:argparse': 0.16; 'then:': 0.16; 'uncommon': 0.16; '(i.e.': 0.17; 'wrote:': 0.18; 'input': 0.22; 'header:In- Reply-To:1': 0.22; 'string': 0.24; 'command': 0.24; 'right.': 0.25; "wasn't": 0.25; 'value.': 0.28; 'explicit': 0.29; 'cases': 0.32; 'words,': 0.32; 'header:User-Agent:1': 0.33; 'too': 0.33; 'received:84': 0.34; 'done': 0.34; 'especially': 0.34; 'integer': 0.34; 'reply-to:addr:python.org': 0.34; 'to:addr:python-list': 0.35; "we're": 0.36; 'run': 0.37; 'but': 0.37; 'some': 0.38; 'think': 0.38; 'should': 0.38; 'that.': 0.39; 'subject:from': 0.39; 'cannot': 0.39; 'point': 0.40; 'user': 0.40; 'to:addr:python.org': 0.40; 'type': 0.61; 'more': 0.61; 'talking': 0.62; 'our': 0.63; 'header:Reply-To:1': 0.70; 'reply-to:no real name:2**0': 0.72; 'article,': 0.84; 'have?': 0.84; 'proposal.': 0.91
X-CM-Score 0.00
X-CNFS-Analysis v=2.0 cv=Dp/UCRD+ c=1 sm=1 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=qePWxsfFzlIA:10 a=QlRFm4pJbugA:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=lPu4ozQ-is_4PrhwyOIA:9 a=wPNLvfGTeEIA:10 a=0nF1XD0wxitMEM03M9B4ZQ==:117
X-AUTH mrabarnett:2500
Date Wed, 14 Mar 2012 17:26:19 +0000
From MRAB <python@mrabarnett.plus.com>
User-Agent Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20120216 Thunderbird/10.0.2
MIME-Version 1.0
To python-list@python.org
Subject Re: Enchancement suggestion for argparse: intuit type from default
References <jjocvo$5i2$1@panix2.panix.com> <87zkbkgp67.fsf@benfinney.id.au> <4f6094c5$0$29972$c3e8da3$5496439d@news.astraweb.com> <87399bgw18.fsf@benfinney.id.au> <roy-AEEEC5.09304414032012@news.panix.com>
In-Reply-To <roy-AEEEC5.09304414032012@news.panix.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To python-list@python.org
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.641.1331745833.3037.python-list@python.org> (permalink)
Lines 47
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1331745833 news.xs4all.nl 6855 [2001:888:2000:d::a6]:40922
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:21613

Show key headers only | View raw


On 14/03/2012 13:30, Roy Smith wrote:
> In article<87399bgw18.fsf@benfinney.id.au>,
>   Ben Finney<ben+python@benfinney.id.au>  wrote:
>
>>  Right. I dislike proposals for run-time type inference in Python, since
>>  they are too magical.
>>
>>  Especially since we're talking about user input (arguments from the
>>  command line to the program); that requires more explicit declarations
>>  and checking, not less.
>>
>>  >  What if you want an argument --foo that will accept arbitrary types? Then
>>  >  you would need some way to tell argparse not to infer the type from the
>>  >  default.
>>
>>  So we would then need to special-case the special-case? Even more reason
>>  to dislike this proposal.
>>
>>  >  Explicit declarations should be used only for the uncommon cases where
>>  >  type inference cannot cope.
>>
>>  That's our point of disagreement, then: I think explicit declarations
>>  should be required regarding user input.
>
> I wasn't suggesting that the type be inferred from what the user
> entered.  I was suggesting it be inferred from what the programmer had
> done (i.e. what value they had given the 'default' parameter).
>
In other words, if there's a default but no explicit type, then the
type is the type of the default.

> It's already inferred that the type is a string if you don't give it any
> value.  What possible meaning could:
>
> parser.add_argument('--foo', default=100)
>
> have?  If I run the program with:
>
> $ prog
>
> then foo defaults to the integer 100, but if I run it with:
>
> $ prog --foo=100
>
> then I get the string "100"?  Surely there's not much of a use case for
> that.

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