[Python-Dev] Major revision of PEP 348 committed
mwh at python.net
Tue Aug 9 11:50:08 CEST 2005
Steven Bethard <steven.bethard at gmail.com> writes:
> Raymond Hettinger wrote:
>> If the PEP can't resist the urge to create new intermediate groupings,
>> then start by grepping through tons of Python code to find-out which
>> exceptions are typically caught on the same line. That would be a
>> worthwhile empirical study and may lead to useful insights.
> I was curious, so I did a little grepping (ok, os.walking and
> re.findalling) ;-) through the Python source. The only exceptions
> that were caught together more than 5 times were:
> AttributeError and TypeError (23 instances) in
> Though these occur in a few different contexts, one relatively common
> one was when the code tried to set a possibly read-only attribute.
This TypeError/AttributeError one is long known, and a bit of a mess,
really. Finding an attribute usually fails because the object is not
of the expected type, after all.
> ImportError and AttributeError (9 instances), in
> This seemed to be used when an incompatible module might be present.
> (Attributes were tested to make sure the module was the right one.)
> Also used when code tried to use "private" module attributes (e.g.
This seems like ever-so-faintly lazy programming to me, but maybe
that's overly purist.
> OverflowError and ValueError (9 instances), in
> These were generally around a call to int(x). I assume they're
> generally unnecessary now that int() silently converts to longs.
Yes, I think so.
> IOError and OSError (6 instances), in
> These were all around file/directory handling that I didn't study in
> too much detail. With the current hierarchy, there's no reason these
> couldn't just be catching EnvironmentError anyway.
Heh. I'd have to admit that I rarely know which of IOError or OSError
I should be expecting in a given situation, nor that EnvironmentError
is a common subclass that I could catch instead...
> Anyway, I know PEP 348's been scaled back at this point anyway, but I
> figured I might as well post my findings in case anyone was curious.
Was interesting, thanks!
<freeside> On a scale of One to AWESOME, twisted.web is PRETTY
ABSTRACT!!!! -- from Twisted.Quotes
More information about the Python-Dev