Hi All,
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
I'm curious why this syntax is allowed? I'm sure there are good reasons, but thought I'd ask...
Chris
On Friday, February 8, 2013 at 10:39 AM, Chris Withers wrote:
Hi All,
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
I'm guessing this gets parsed as sometotal = +somevalue
I'm curious why this syntax is allowed? I'm sure there are good reasons, but thought I'd ask...
Chris
-- Simplistix - Content Management, Batch Processing & Python Consulting
Python-Dev mailing list Python-Dev@python.org (mailto:Python-Dev@python.org) http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/donald.stufft%40gmail.com
2013/2/8 Chris Withers chris@simplistix.co.uk:
Hi All,
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
That's just a strange way of expressing
sometotal = +somevalue
I'm curious why this syntax is allowed? I'm sure there are good reasons, but thought I'd ask...
On Sat, Feb 9, 2013 at 2:39 AM, Chris Withers chris@simplistix.co.uk wrote:
Hi All,
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
I'm curious why this syntax is allowed? I'm sure there are good reasons, but thought I'd ask...
For the same reason that you can negate a value with:
sometotal = -somevalue
The unary + and - operators are seldom problematic.
ChrisA
On 2013-02-08, at 16:39 , Chris Withers wrote:
Hi All,
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
I'm curious why this syntax is allowed? I'm sure there are good reasons, but thought I'd ask…
sometotal = (expression) is valid syntax, and +value is valid syntax.
Thus what you wrote is perfectly normal syntax, it's the assignment of a pos'd value, badly formatted. pep8.py will warn against it (it'll complain that the whitespace around `+` is wonky). But I see no justification for disallowing this, anymore than for disallowing the rougly equivalent (and just as error-prone) `sometotal = -somevalue`.
On 8 February 2013 15:39, Chris Withers chris@simplistix.co.uk wrote:
Hi All,
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
I'm curious why this syntax is allowed? I'm sure there are good reasons, but thought I'd ask...
Because '+' can represent an unary prefix operator just the same as '-':
- -- ++- +- -+ ++3
-3
Oscar
On 08.02.13 17:39, Chris Withers wrote:
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
I'm curious why this syntax is allowed? I'm sure there are good reasons, but thought I'd ask...
And why this syntax is allowed?
pi = 3,14
And this:
fruits = [ 'apple', 'pear', 'banana' 'ananas', 'mango' ]
On 08/02/2013 15:42, Benjamin Peterson wrote:
2013/2/8 Chris Witherschris@simplistix.co.uk:
Hi All,
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
That's just a strange way of expressing
sometotal = +somevalue
Indeed, but why should this be possible? When could it do something useful? :-)
Chris
2013/2/8 Chris Withers chris@simplistix.co.uk:
On 08/02/2013 15:42, Benjamin Peterson wrote:
2013/2/8 Chris Witherschris@simplistix.co.uk:
Hi All,
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
That's just a strange way of expressing
sometotal = +somevalue
Indeed, but why should this be possible? When could it do something useful? :-)
+ is a normal overridable operator.
On 8 February 2013 16:10, Benjamin Peterson benjamin@python.org wrote:
2013/2/8 Chris Withers chris@simplistix.co.uk:
On 08/02/2013 15:42, Benjamin Peterson wrote:
2013/2/8 Chris Witherschris@simplistix.co.uk:
Hi All,
Just had a bit of an embarrassing incident in some code where I did:
sometotal =+ somevalue
That's just a strange way of expressing
sometotal = +somevalue
Indeed, but why should this be possible? When could it do something useful? :-)
- is a normal overridable operator.
Decimal.__pos__ uses it to return a Decimal instance that has the default precision of the current Decimal context:
from decimal import Decimal d = Decimal('0.33333333333333333333333333333333333333') d
Decimal('0.33333333333333333333333333333333333333')
+d
Decimal('0.3333333333333333333333333333')
Oscar
On 08/02/2013 16:17, Oscar Benjamin wrote:
Decimal.__pos__ uses it to return a Decimal instance that has the default precision of the current Decimal context:
from decimal import Decimal d = Decimal('0.33333333333333333333333333333333333333') d
Decimal('0.33333333333333333333333333333333333333')
+d
Decimal('0.3333333333333333333333333333')
That's the answer I was hoping wouldn't be coming...
Oh well, guess I'll have to improve on my sloppy typing.
Chris
On 2013-02-08, at 18:45 , Chris Withers wrote:
On 08/02/2013 16:17, Oscar Benjamin wrote:
Decimal.__pos__ uses it to return a Decimal instance that has the default precision of the current Decimal context:
from decimal import Decimal d = Decimal('0.33333333333333333333333333333333333333') d
Decimal('0.33333333333333333333333333333333333333')
+d
Decimal('0.3333333333333333333333333333')
That's the answer I was hoping wouldn't be coming...
Oh well, guess I'll have to improve on my sloppy typing.
Or just run flake8 (with a bit of configuration to disable the annoying stuff).
On Feb 8, 2013 3:37 PM, "Xavier Morel" catch-all@masklinn.net wrote:
On 2013-02-08, at 18:45 , Chris Withers wrote:
On 08/02/2013 16:17, Oscar Benjamin wrote:
Decimal.__pos__ uses it to return a Decimal instance that has the default precision of the current Decimal context:
from decimal import Decimal d = Decimal('0.33333333333333333333333333333333333333') d
Decimal('0.33333333333333333333333333333333333333')
+d
Decimal('0.3333333333333333333333333333')
That's the answer I was hoping wouldn't be coming...
Oh well, guess I'll have to improve on my sloppy typing.
Or just run flake8 (with a bit of configuration to disable the annoying
stuff).
As flake8's maintainer, I second this.