Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.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.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'syntax': 0.03; 'value,': 0.03; 'argument': 0.04; 'test,': 0.05; 'clause': 0.07; 'exception.': 0.07; 'none)': 0.07; 'behavior,': 0.09; 'subject:while': 0.09; 'tuple': 0.09; 'tuple.': 0.09; 'assignments.': 0.16; 'determining': 0.16; 'element.': 0.16; 'oct': 0.16; 'subject:expression': 0.16; 'tuple,': 0.16; 'wrote:': 0.17; 'element': 0.17; 'assignment': 0.22; 'idea': 0.24; 'testing': 0.24; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'question': 0.27; 'necessary.': 0.27; 'message- id:@mail.gmail.com': 0.27; 'there.': 0.28; 'run': 0.28; 'dan': 0.29; 'existence': 0.29; 'mind,': 0.29; 'though.': 0.29; 'fri,': 0.30; 'function': 0.30; 'expect': 0.31; 'print': 0.32; 'extract': 0.33; 'raising': 0.33; 'true.': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.34; 'received:google.com': 0.34; 'fail': 0.35; 'false': 0.35; 'so,': 0.35; 'doing': 0.35; 'received:209.85': 0.35; 'there': 0.35; 'test': 0.36; 'should': 0.36; 'received:209': 0.37; 'subject:: ': 0.38; 'perform': 0.38; 'to:addr:python.org': 0.39; 'header:Received:5': 0.40; 'think': 0.40; 'remove': 0.61; 'first': 0.61; '26,': 0.65; 'surprise': 0.65; 'truth': 0.75; 'to:name:python': 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 :content-type; bh=/MvOcodtRDVQjT/DLy+e4VdHxp7FSbFwhyLGIxxOzw4=; b=asYWUiL/oqLzoyem1pGzhaOo9zKXCdl6oODRqZ8CFJl/2wfakf77tcEo7qZt5cDK5f KNqlgfNi/fTHcz1lVu1PVHtOVuVgml3gPoSoAApqMpt6/ywGjIHIZntPK/MlhZlU+STj WyBFO9XrQG2xiq/frIecOIgDmNbT1w9rqtCW4WeiR7f99sG6VpZd/YoOIMSTLv1gqBUF 4pHTs8b2VQLSDfmRAKB4x8lcWiC1L0tTdtqSmk7ThxNRCGvObFaEzszKydtAByfgpoq8 8RshgIvudDbN/8yh2jOLac+gRjaKozeLtPzxiFnYSRpUHN6xAwCZEwpChGVq/VUQaZ5/ FPRA== MIME-Version: 1.0 In-Reply-To: <31566ce7-bfba-4bcb-aecf-2586ec579390@googlegroups.com> References: <50886398.5050301@tim.thechases.com> <7x7gqf1na2.fsf@ruckus.brouhaha.com> <7x7gqdzs1i.fsf@ruckus.brouhaha.com> <31566ce7-bfba-4bcb-aecf-2586ec579390@googlegroups.com> From: Ian Kelly Date: Fri, 26 Oct 2012 09:42:28 -0600 Subject: Re: while expression feature proposal To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 23 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351266181 news.xs4all.nl 6932 [2001:888:2000:d::a6]:53057 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32220 On Fri, Oct 26, 2012 at 9:29 AM, Dan Loewenherz wrote: > while client.spop("profile_ids") as truthy, profile_id: > if not truthy: > break > > print profile_id > > Here, client.spop returns a tuple, which will always returns true. We then extract the first element and run a truth test on it. The function we use is in charge of determining the truthiness. I don't like the idea of testing the first element. There's a large element of surprise in doing that, I think. I would expect the truth test to be the same with or without the existence of the "as" clause there. That is, you should be able to remove the "as" clause and have exactly the same behavior, just without the assignments. So it would need to test the entire tuple. That brings up an interesting additional question in my mind, though. Should the while loop syntax attempt to perform the assignment on the very last test, when the expression is false? I think there is a good argument for doing so, as it will allow additional inspection of the false value, if necessary. In the above, though, if the return value is false (an empty tuple or None) then the assignment would fail during unpacking, raising an exception.