Re Being Pythonic [ was Re: [MERGE] The eol functionality now issues a warning if a rule is configured (bug 358199) ]
Barry Warsaw
barry at python.org
Sat Apr 18 15:40:24 BST 2009
On Apr 18, 2009, at 3:49 AM, Russel Winder wrote:
> OK I am intrigued why is:
>
> if filter is None : . . .
>
> more Pythonic than:
>
> if filter == None : . . .
Because None is a 'singleton' and it's considered better style to
comparison test against singletons using identity testing. This is
similar to another common idiom:
missing = object()
value = mydict.get(key, missing)
if value is missing:
# ...which as the additional benefit of reading very nicely
As mentioned elsewhere (I think), you can't get hit with broken
__eq__'s and identity testing is unnoticeably faster <wink>.
-Barry
-------------- next part --------------
A non-text attachment was scrubbed...
Name: PGP.sig
Type: application/pgp-signature
Size: 304 bytes
Desc: This is a digitally signed message part
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20090418/5eca9337/attachment.pgp
More information about the bazaar
mailing list