[Python-Dev] Deprecating string exceptions
Barry A. Warsaw
barry@zope.com
Thu, 28 Mar 2002 00:02:16 -0500
>>>>> "Fred" == Fred L Drake, Jr <fdrake@acm.org> writes:
Fred> Except of course that it *will* work in Python version
Fred> dating back to (I suspect) 1.0; that certainly was being
Fred> done in 1.2, though I don't think it was ever recommended
Fred> practice.
Fred> That it worked before string interning was an accident of
Fred> implementation: all the 'foo' in your example were in a
Fred> single code object, and so were ensured by the compiler to
Fred> be the same object (they shared an entry in the constants
Fred> table). After string interning was added, it worked more
Fred> broadly because interning caused a single 'foo' to be
Fred> shared.
Of course the first 'foo' and the second 'foo' need not have such a
close lexical relationship. And can't interning (I think) be
disabled? (Though I'm sure no one does this.) Also, isn't interning
limited to just identifier-like strings:
>>> x = 'foo += boy'
>>> y = 'foo += boy'
>>> x is y
0
So, yes the simple example I gave will work, but the more general
concept, that string exceptions cannot guaranteed to be caught by
value, still holds.
-Barry