<DKIM> [BUG] function argument set to an object
Nicolas Sebrecht
nicolas.s-dev at laposte.net
Mon Dec 19 11:59:38 GMT 2016
On Mon, Dec 19, 2016 at 07:06:17AM +0000, Luke Kenneth Casson Leighton wrote:
> 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.
Looks correct analisys to me. I didn't check how this issue impacts the
code, though.
--
Nicolas Sebrecht
More information about the OfflineIMAP-project
mailing list