Re: [Mailman-Developers] [Mailman-checkins] [Branch ~mailman-coders/mailman/2.2] Rev 1046: - Changed some old messages for more current meaning.
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mar 14, 2009, at 6:22 PM, noreply@launchpad.net wrote:
@@ -510,6 +507,12 @@ try: msgfp = open(pckfile) msg = cPickle.load(msgfp) + if data == {}:
This looks a little Pythonically weird; maybe if len(data) == 0 instead?
+ # There was no .db file. Is this a post 2.1.5 .pck? + try: + data = cPickle.load(msgfp) + except EOFError: + pass os.unlink(pckfile) except EnvironmentError, e: if e.errno <> errno.ENOENT: raise
Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (Darwin) iQCVAwUBSbw52nEjvBPtnXfVAQKhmQP/aZDty8h2jtExUlcSUjsV98zIsxxajO92 ZmxdMc6NQd+42N+ZVvMJqdaQatUUbUArap+gvlLTxuPJOoFe0JjWfed79VMSFwkQ lvmR4EdJTby/tT95U72/w/gKjA/+KH9m6SgHdu06iUGTVaM+pzwLkqQK6/qQKpIY XHaxZpebxZ8= =lsE0 -----END PGP SIGNATURE-----
Barry Warsaw wrote:
On Mar 14, 2009, at 6:22 PM, noreply@launchpad.net wrote:
@@ -510,6 +507,12 @@ try: msgfp = open(pckfile) msg = cPickle.load(msgfp) + if data == {}:
This looks a little Pythonically weird; maybe if len(data) == 0 instead?
Thanks Barry. Actually, I was concerned about the possibility that data could be None, but upon closer inspection, that can't happen, and even if it did, it wouldn't matter, so just if data: should be good. -- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
Mark Sapiro wrote:
Actually, I was concerned about the possibility that data could be None, but upon closer inspection, that can't happen, and even if it did, it wouldn't matter, so just if data: should be good.
Ooops. I mean if not data:
-- Mark Sapiro <mark@msapiro.net> The highway is for gamblers, San Francisco Bay Area, California better use your sense - B. Dylan
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Mar 14, 2009, at 04:40 PM, Mark Sapiro wrote:
Barry Warsaw wrote:
On Mar 14, 2009, at 6:22 PM, noreply@launchpad.net wrote:
@@ -510,6 +507,12 @@ try: msgfp = open(pckfile) msg = cPickle.load(msgfp) + if data == {}:
This looks a little Pythonically weird; maybe if len(data) == 0 instead?
Actually, I was concerned about the possibility that data could be None, but upon closer inspection, that can't happen, and even if it did, it wouldn't matter, so just if data: should be good.
Hi Mark, A style I've adopted for MM3 is that if the object is definitely supposed to be a sequence, emptiness is checked with len(). E.g. for a string, list, tuple, dictionary, you'd use: if len(data) == 0: If the object could be a sequence or None, then bare if would be used, but I generally add a comment to explain things, e.g.: # data could be an empty dictionary or None if not data: What do you think? MM2 is pretty inconsistent here so I'm not sure whether it's worth adopting or (in 2.2) converting to this style. Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) iEYEARECAAYFAkm+ieEACgkQ2YZpQepbvXG5kgCgssRqZ73I6YuWWJOCd6RRjK+v g4UAnR/qLSW52K9vVrqkWEVSw4Sp9yXd =1o90 -----END PGP SIGNATURE-----
Barry Warsaw writes:
A style I've adopted for MM3 is that if the object is definitely supposed to be a sequence, emptiness is checked with len(). E.g. for a string, list, tuple, dictionary, you'd use:
if len(data) == 0:
If the object could be a sequence or None, then bare if would be used, but I generally add a comment to explain things, e.g.:
# data could be an empty dictionary or None if not data:
If you document the style in a developer's guide or something like that, I'd rather not have the comment every time. "None" would seem to indicate "Yo! Initialize me!", and you'd check for that with "if data is None". "if not data" would be the case where either there never was anything to do, or nothing is left to do, so stop doing it. And if len(data) == 0 is a terminal condition for initialized data. So I don't think you need the comment.
Or are there other usages you have in mind that I've missed?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On Mar 17, 2009, at 03:03 AM, Stephen J. Turnbull wrote:
If you document the style in a developer's guide or something like that, I'd rather not have the comment every time.
That's a good point, and I do intend to update the Mailman style guide to cover this.
"None" would seem to indicate "Yo! Initialize me!", and you'd check for that with "if data is None".
Exactly right.
"if not data" would be the case where either there never was anything to do, or nothing is left to do, so stop doing it. And if len(data) == 0 is a terminal condition for initialized data. So I don't think you need the comment.
Or are there other usages you have in mind that I've missed?
Nope, that about covers it. So maybe the comment is overkill given a(n updated) style guide to work from.
Barry -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux)
iEYEARECAAYFAkm+oyAACgkQ2YZpQepbvXGHCQCfdYsd5pD56cIirnqGPZ+sOBUa woIAn2D4cpKo7/Bj++c7cXQEQr+Zysu3 =8SKO -----END PGP SIGNATURE-----
participants (4)
-
Barry Warsaw
-
Barry Warsaw
-
Mark Sapiro
-
Stephen J. Turnbull