Re Being Pythonic [ was Re: [MERGE] The eol functionality now issues a warning if a rule is configured (bug 358199) ]
Forest Bond
forest at alittletooquiet.net
Sat Apr 18 12:21:51 BST 2009
Hi,
On Sat, Apr 18, 2009 at 08:49:36AM +0100, Russel Winder wrote:
> On Fri, 2009-04-17 at 14:11 -0500, John Arbash Meinel wrote:
>
> > ^- as a 'pythonic' thing, you should always use 'is' to compare with
> > None, so it would be:
> >
> > if filter is None:
> > ...
>
> OK I am intrigued why is:
>
> if filter is None : . . .
>
> more Pythonic than:
>
> if filter == None : . . .
It is a common idiom, in my experience, to say "if foo is None".
Otherwise, it is slightly better:
* is does the right thing even if foo has a broken __eq__ implementation.
* is should be faster, since it only has to compare ids, not potentially call
__eq__, __cmp__, etc.
-Forest
--
Forest Bond
http://www.alittletooquiet.net
http://www.pytagsfs.org
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20090418/f0dc49c7/attachment.pgp
More information about the bazaar
mailing list