[BUG] function argument set to an object

Luke Kenneth Casson Leighton lkcl at lkcl.net
Mon Dec 19 07:06:17 GMT 2016


aiyaaa!  mustn't do this!  it's the "pattern" for a singleton:

LocalStatusSQLite.py (and probably LocalStatus.py as well):
    def savemessage(self, uid, content, flags, rtime, mtime=0, labels=set()):


example:

>>> def singleton(val, x = set()):
...     x.add(val)
...     return x
...
>>> singleton(5)
set([5])
>>> singleton(7)
set([5, 7])

baad, veryverybaad :)  so, any time that labels are used, if you
happen *not* to have that last argument in calling savemessage but
there are instances where it is, things go horribly badly wrong
because the labels= argument ends up STORING prior labels in that
set()...


must do this instead:

>>> def notasingleton(val, x=None):
...     if x is None:
...             x = set()
...     x.add(val)
...     return x
...
>>> notasingleton(5)
set([5])
>>> notasingleton(7)
set([7])
>>> y = set()
>>> notasingleton(7, y)
set([7])
>>> notasingleton(5, y)
set([5, 7])

will submit a patch later, am in the middle of the first lmdb revision.

l.

--
-- http://crowdsupply.com/eoma68 eco-conscious computing




More information about the OfflineIMAP-project mailing list