[RFC] use optparse for option handling

Aaron Bentley aaron.bentley at utoronto.ca
Thu Jul 13 06:22:44 BST 2006


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

Hi Ben,

Ben Finney wrote:
>> (btw, is there a way to prevent that string from being interned?  I
>> don't want false negatives from
>> "if v is not OptionParser.DEFAULT_VALUE")
> 
> If you really want to check *identity*, use 'is' and 'is
> not'.

I really want to check identity.  I want to be able to use
OptionParser.DEFAULT_VALUE as a special object, the same way None is
used.  I don't want to use None in this context, because None already
has a different meaning.

> Otherwise, use '=' and '!='.
> 
> You'll get no false negatives from "if v != OptionParser.DEFAULT_VALUE".

This misunderstands the test.  I want the test to evaluate to True if v
is another object with the same value as OptionParser.DEFAULT_VALUE.  It
should only evaluate to False if v and OptionParser.DEFAULT_VALUE are
two names for the same object.

The problem is that I'm currently using a string as the value of
OptionParser.DEFAULT_VALUE, and due to Python's aggressive interning:

>>> 'red' is not 'red'
False

Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEtdik0F+nu1YWqI0RAp2OAJ9RQO2gf+lOhaHn3Iae0aujbRWaRgCeP+0k
F5rRuOCNFbCC08EzilZ6Xms=
=bz79
-----END PGP SIGNATURE-----




More information about the bazaar mailing list