[Python-Dev] os.path.walk() lacks 'depth first' option

Tim Peters tim.one@comcast.net
Tue, 13 May 2003 15:03:58 -0400


[Christian Tanzer]
> More hmmm...
>
> Just grepped over my source tree (1293 .py files, ~ 300000 lines):
>
> - 45 occurrences of `except AttributeError` with no mention of
>   `TypeError`
>
> - 16 occurrences of `except TypeError` with no mention of
>   `AttributeError`
>
> - 3 occurrences of `except (AttributeError, TypeError)`
>
> Works well enough for me.

With a fixed release of Python, it would be hard not to work well enough.  I
have to point out, though, that *across* Python releases, a frequent kind of
patch made to the Python test suite is changing former TypeError occurrences
to AttributeError, or vice versa.  I'm not sure which direction is most
common overall, and it's often unclear which is more appropriate.  For
example,

>>> d = {}
>>> d.update('abc')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: keys
>>>

I wouldn't be surprised if that changed to TypeError someday.

> Deriving both AttributeError and TypeError from a common base would
> make sense to me. Merging them wouldn't.

Yes -- and we should derive all exceptions from LookupError <wink>.