Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!goblin3!goblin.stu.neva.ru!news.cgarbs.de!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python,': 0.01; 'operator': 0.05; '>>>>': 0.09; 'bind': 0.09; 'prevents': 0.09; '(not,': 0.16; 'binary,': 0.16; 'conceivably': 0.16; 'expression,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'mean,': 0.16; 'parentheses': 0.16; 'tendency': 0.16; 'two?': 0.16; 'unary': 0.16; 'wrote:': 0.16; 'continuing': 0.17; 'wed,': 0.17; 'header:In-Reply-To:1': 0.22; "shouldn't": 0.23; 'pm,': 0.24; 'aug': 0.24; 'statement': 0.25; 'putting': 0.28; 'message-id:@mail.gmail.com': 0.29; 'example': 0.30; 'binding': 0.30; 'operand': 0.30; 'theatre': 0.30; 'least': 0.31; 'chris': 0.32; 'expression': 0.32; 'does': 0.32; "can't": 0.33; 'to:addr:python-list': 0.33; 'that,': 0.33; 'operating': 0.33; "i've": 0.34; 'however,': 0.34; '...': 0.34; 'right,': 0.34; 'rather': 0.35; 'beginning': 0.36; 'rest': 0.37; 'but': 0.37; 'something': 0.37; 'could': 0.38; 'think': 0.38; 'steven': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'skip:o 20': 0.38; 'subject:: ': 0.39; "there's": 0.39; 'to:addr:python.org': 0.39; 'case': 0.39; "it's": 0.40; 'your': 0.61; 'leading': 0.61; 'plus': 0.65; 'ever': 0.65; 'legal': 0.70; 'imagine': 0.71; 'subject:line': 0.73; 'illustrated': 0.84; 'so:': 0.84; '(42': 0.91; '120,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=rCiw/H7zQWQdb2VtCFztXrvi374T5Ip6l0USaIWv7rU=; b=ZaF7c8Z9Avt0Y7Cj/eHMyNMcyUCZqBmJabzhNdRKoXHo32P4QhZk1I5IgPwE2HnwrM Nax7+PosWRwVGt2lMXwQFD5xFYu9g4uz+R4j7OBHnLDn9IKjexaec3GbwLEbZ3tveqX5 7H72O1aPwXg1fyiQDYqDJ7yGfnTCDgNEEP6Sk= MIME-Version: 1.0 In-Reply-To: <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> <4e4297be$0$29993$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 10 Aug 2011 16:13:42 +0100 Subject: Re: allow line break at operators From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable 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: 44 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312989224 news.xs4all.nl 23919 [2001:888:2000:d::a6]:58849 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11133 On Wed, Aug 10, 2011 at 3:37 PM, Steven D'Aprano wrote: >> Without the parentheses, this is legal but (probably) useless; it >> applies the unary + operator to the return value of those functions. >> Putting the + at the end of the previous line at least prevents that, >> since most unary operators bind to the operand on the right; > > Not so: > >>>> x =3D (42 + - > ... =A0 =A0 100) >>>> >>>> x > -58 Your unary - is binding to the operand to its right, in this case the 100. (I think I have left and right correct; being in theatre has a tendency to make you forget which is which.) Your + is binary, operating on 42 and the result of applying unary - to 100, which is -100. My point about binding can be illustrated by inventing an operator @. Let's say that a@b is the atan2 of a and b, and x@ is x factorial (I can't imagine what deranged mind would do something like this, apart from my own). y =3D 5 @ # 120, as per factorial x =3D 5 @ 2 # 1.19 or so, as per atan2 foo(123) # Calls foo() and discards its return value z =3D 5 @ foo(123) Is that last example one statement or two? But this situation shouldn't ever occur in Python, because all its unary operators (not, -, +, ~) bind to the operand to their right (I don't think there's any I've missed, are there?). It does mean, however, that a leading operator is not unambiguous. Without the surrounding parentheses and/or otherwise-unexpected indentation, an expression beginning with a + could conceivably be applying the unary plus operator to the rest of the expression, rather than implying that it's continuing the previous line. Chris Angelico