The augmented arithmetic operations on PgNumeric instances will update the object directly,
instead of creating a new one.
This leads to unexpected results such as:
$ cat t.py
from pyPgSQL.PgSQL import PgNumeric
a = PgNumeric(1.0)
b = a
b += 1
print a, b
$ python t.py
Here we see b is incremented, but both a and b
are changed, because the __iadd__ method updates
b in place.
Call me naive, but I would expect "b += 1"
to behave exactly like "b = b+1".
Perhaps PgNumeric should allocate a new object
if the old one has multiple references?
I'm not sure, but the current behavior
is not intuitive, and leads to hard-to-find bugs.
Log in to post a comment.