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


Groups > comp.lang.python > #66152

Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!)

Path csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.012
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'argument': 0.05; 'one?': 0.05; 'explicit': 0.07; 'function,': 0.09; 'method,': 0.09; 'cc:addr:python-list': 0.11; 'python': 0.11; 'random': 0.14; '(either': 0.16; 'callable': 0.16; 'closure,': 0.16; 'fiddle': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'iterates': 0.16; "object's": 0.16; 'pointer,': 0.16; 'subject: \n ': 0.16; 'subject:More': 0.16; 'wrote:': 0.18; 'any,': 0.19; 'thu,': 0.19; 'feb': 0.22; '>>>': 0.22; 'cc:addr:python.org': 0.22; 'question': 0.24; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'function': 0.29; '[1]': 0.29; "doesn't": 0.30; 'message- id:@mail.gmail.com': 0.30; 'usually': 0.31; '13,': 0.31; 'assert': 0.31; "d'aprano": 0.31; 'implicit': 0.31; 'really,': 0.31; 'steven': 0.31; 'subject:other': 0.31; 'probably': 0.32; 'critical': 0.32; 'actual': 0.34; "can't": 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'data,': 0.36; 'maintained': 0.36; 'object,': 0.36; 'doing': 0.36; 'method': 0.36; 'similar': 0.36; 'two': 0.37; 'skip:[ 10': 0.38; 'pm,': 0.38; 'rather': 0.38; 'anything': 0.39; 'ensure': 0.60; 'name:': 0.61; 'course': 0.61; "you're": 0.61; 'making': 0.63; 'kind': 0.63; 'different': 0.65; 'difficulty': 0.68; 'default': 0.69; 'confirming': 0.84; 'generation,': 0.84; 'proves': 0.84; 'subject:!)': 0.84; 'subject:via': 0.84; 'to:none': 0.92; 'state.': 0.95
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=Xr39bZQHhpQaFgkFS+XLvE2lL6WMJRu//2u0DUsxd9E=; b=m4kpl2m+9tMm1auh4/jd1K0HPljaSGzAxF8ojkpwU/BNh68lOrp5lJmgwBa6aP3lM6 GiO+UP+x0tIXcyuvBSOohGy2FVBKKg3G0tt5pPkq0gqZkxAbj73RoXBAtAPBAkjsgJsT kKkpgt6G6va3qmpsNnZnJY12yyttVpOXVktu/D3CsyIG7RjUhAqEJGmdHjdp5NgNu8L4 pBFHBcy8RNt3ecFvS2EroD87aurpB+W+gC5ncWyzWql7CZ7SPK9bIQMPkcOB0lOVK47E fBOCQJwAHRPfRMX828T+Q6VrvzXEGfwnOzhaIUZTtk5d+DpjTsIp4EpN5jDGElfolWOQ K2Tg==
MIME-Version 1.0
X-Received by 10.66.118.71 with SMTP id kk7mr43623631pab.14.1392265856303; Wed, 12 Feb 2014 20:30:56 -0800 (PST)
In-Reply-To <52fc45e6$0$11128$c3e8da3@news.astraweb.com>
References <85c2698c-d681-4511-b111-bb1e549ece93@googlegroups.com> <52f9c392$0$11128$c3e8da3@news.astraweb.com> <mailman.6677.1392133008.18130.python-list@python.org> <52fc45e6$0$11128$c3e8da3@news.astraweb.com>
Date Thu, 13 Feb 2014 15:30:56 +1100
Subject Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!)
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <python-list@python.org>
Content-Type text/plain; charset=UTF-8
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.6824.1392265865.18130.python-list@python.org> (permalink)
Lines 44
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1392265865 news.xs4all.nl 2839 [2001:888:2000:d::a6]:52168
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:66152

Show key headers only | View raw


On Thu, Feb 13, 2014 at 3:11 PM, Steven D'Aprano <steve@pearwood.info> wrote:
> Think about the difference in difficulty in confirming that
> math.sin() of some value x returns the value 0.5, and confirming that
> random.random() of some hidden state returns a specific value:
>
> py> assert math.sin(0.5235987755982989) == 0.5
>
> versus:
>
> py> state = random.getstate()
> py> random.seed(12345)
> py> assert random.random() == 0.41661987254534116
> py> random.setstate(state)

Really, the assertion just requires the setting of the seed and the
call to random.random(); the other two are to ensure that you don't
fiddle with anything else that's using random.random(). And since
random.random() is actually just a bound method of some module-level
object, you can actually just create the exact same thing with
explicit rather than implicit state:

>>> random.Random(12345).random()
0.41661987254534116

Which doesn't tamper with the default object's state.

Whether it's a module-level function, a bound method, a closure, or a
callable object, a zero-arg function in Python always has some kind of
implicit state. The question is, what is it doing with it? In the case
of random number generation, maintained state is critical (and making
it implicit is usually sufficient); similar with functions like
input(), where the return value doesn't really depend on the argument
at all [1], and of course anything that iterates over an object is
going to need to change some kind of state (either a pointer, or the
actual data, depending on whether you're looking at eg
iter([1,2,3]).next or [1,2,3].pop). Do you know of any functions in
Python that don't use any implicit state and don't take arguments? I
can't think of any, but of course that proves nothing.

ChrisA

[1] input("Enter your name: ") vs input("What is one plus one? ") will
probably return different values, but that's playing with humans
rather than depending on the value of the argument...

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Rick Johnson <rantingrickjohnson@gmail.com> - 2014-02-10 10:45 -0800
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-02-10 19:15 +0000
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Ned Batchelder <ned@nedbatchelder.com> - 2014-02-10 14:17 -0500
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Rotwang <sg552@hotmail.co.uk> - 2014-02-10 21:12 +0000
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Ned Batchelder <ned@nedbatchelder.com> - 2014-02-10 17:00 -0500
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Terry Reedy <tjreedy@udel.edu> - 2014-02-10 17:59 -0500
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-11 09:30 +1100
  Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Steven D'Aprano <steve@pearwood.info> - 2014-02-11 06:30 +0000
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Tim Chase <python.list@tim.thechases.com> - 2014-02-11 09:26 -0600
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Travis Griggs <travisgriggs@gmail.com> - 2014-02-11 07:36 -0800
      Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-02-11 18:07 +0200
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-12 03:14 +1100
      Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Steven D'Aprano <steve@pearwood.info> - 2014-02-13 04:11 +0000
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-13 15:30 +1100
          Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Roy Smith <roy@panix.com> - 2014-02-13 09:58 -0500
            Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-14 06:17 +1100
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Tim Chase <python.list@tim.thechases.com> - 2014-02-13 05:39 -0600
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Tim Chase <python.list@tim.thechases.com> - 2014-02-13 05:51 -0600
        Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Ian Kelly <ian.g.kelly@gmail.com> - 2014-02-13 15:00 -0700
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Chris Angelico <rosuav@gmail.com> - 2014-02-12 02:52 +1100
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Travis Griggs <travisgriggs@gmail.com> - 2014-02-11 08:19 -0800
    Re: PyWart: More surpises via "implict conversion to boolean" (and other steaming piles!) Terry Reedy <tjreedy@udel.edu> - 2014-02-11 12:57 -0500

csiph-web