A Bug By Any Other Name ...
Lie Ryan
lie.1296 at gmail.com
Tue Jul 7 00:51:51 EDT 2009
Chris Rebert wrote:
> On Mon, Jul 6, 2009 at 1:29 AM, Lawrence
> D'Oliveiro<ldo at geek-central.gen.new_zealand> wrote:
>> In message <mailman.2674.1246866966.8015.python-list at python.org>, Tim Golden
>> wrote:
>>
>>> The difficulty here is knowing where to put such a warning.
>>> You obviously can't put it against the "++" operator as such
>>> because... there isn't one.
>> This bug is an epiphenomenon. :)
>
> Well, like I suggested, it /could/ be made an operator (or rather, a
> lexer token) which just causes a compile/parse error.
>
> Cheers,
> Chris
There are edge cases (level: very rare) where you legitimately want to
actually do that, e.g.:
class A(object):
def __init__(self, arg):
self.value = arg.value
def __pos__(self):
return B(self)
def __neg__(self):
return D(self)
class B(object):
def __init__(self, arg):
self.value = arg.value
def __pos__(self):
return C(self)
def __neg__(self):
return A(self)
class C(object):
def __init__(self, arg):
self.value = arg.value
def __pos__(self):
return D(self)
def __neg__(self):
return B(self)
class D(object):
def __init__(self, arg):
self.value = arg.value
def __pos__(self):
return A(self)
def __neg__(self):
return C(self)
def cons(val):
class E(object):
value = val
return E()
>>> a = A(cons(10))
>>> +a
<__main__.B object at 0x7fbf723c8690>
>>> ++a
<__main__.C object at 0x7fbf723c8710>
>>> +++a
<__main__.D object at 0x7fbf723c8710>
>>> --a
<__main__.C object at 0x7fbf723c8710>
More information about the Python-list
mailing list