[MERGE] Fix test suite regression on OSX in TestReadMergeableFromUrl.test_smart_server_connection_reset.

John Arbash Meinel john at arbash-meinel.com
Wed Oct 1 15:03:24 BST 2008


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

...

>> I've been bitten by that in another project (I used 'is' here by
>> copy/paste, I should have known better :) and I was wondering:
>> using 'is' seems to be an optimized path when both strings are
>> interned, but '==' should knows that and use it, so is it really
>> worth trying to use 'is' ? And if yes, in what contexts ?
> 
> “is” is useful in two cases that I can think of:
> 
>   * when you really do want to know if one object is the same instance
>     as another.  Use cases are things like implementing object
>     serialisers like pickle, or maybe caching/memoising mechanisms, or
>     debug tools.
> 
>   * when being as fast as possible is important, and you are *sure* that
>     “is” will give the correct answer in this case.
> 
> -Andrew.

The big one here is "is None". Occasionally you'll have a sentinel
object like:

_sentinel = object()

def foo():
  if X is true:
    return _sentinel


and then the caller can do

result = foo()
if result is _sentinel:
  # something special happened

John
=:->





-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkjjgywACgkQJdeBCYSNAAP7FQCgtpNU8Kfy/a28Cp81dD0VBDdQ
HuUAn2MiS7Tev1OJnOaa6fx8D8JvOYyf
=LJLO
-----END PGP SIGNATURE-----



More information about the bazaar mailing list