A Bug By Any Other Name ...

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Tue Jul 7 08:00:33 EDT 2009


On Mon, 06 Jul 2009 22:18:20 -0700, Chris Rebert wrote:

>> Not so rare. Decimal uses unary plus. Don't assume +x is a no-op.
[...]
> Well, yes, but when would you apply it twice in a row?

My point was that unary + isn't a no-op, and therefore neither is ++. For 
Decimal, I can't think why you'd want to apply ++x, but for other 
objects, who knows?

Here's a toy example:

>>> class Spam(str):
...     def __pos__(self):
...         return self.__class__("spam " + self)
...
>>> s = Spam("")
>>> ++++s
'spam spam spam spam '



-- 
Steven



More information about the Python-list mailing list