A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from http://mail.python.org/pipermail/python-dev/2002-March/021827.html below:

[Python-Dev] Deprecating string exceptions

[Python-Dev] Deprecating string exceptionsFred L. Drake, Jr. fdrake@acm.org
Wed, 27 Mar 2002 23:38:05 -0500
Barry A. Warsaw writes:
 > That's kind of scary Skip!  I.e. I belive the following is /not/
 > guaranteed to work in any version of Python that I'm aware of:
 > 
 >     try:
 > 	raise 'foo'
 >     except 'foo':
 > 	print 'foo caught'
 > 
 > because 'foo' is not (necessarily) 'foo'.

Except of course that it *will* work in Python version dating back to
(I suspect) 1.0; that certainly was being done in 1.2, though I don't
think it was ever recommended practice.

That it worked before string interning was an accident of
implementation: all the 'foo' in your example were in a single code
object, and so were ensured by the compiler to be the same object
(they shared an entry in the constants table).  After string interning
was added, it worked more broadly because interning caused a single
'foo' to be shared.

I'd *love* to see a warning issued everywhere a string exception is
raised or caught by a non-bare except clause!


  -Fred

-- 
Fred L. Drake, Jr.  <fdrake at acm.org>
PythonLabs at Zope Corporation



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4