[Python-Dev] Attribute error: providing type name

"Martin v. Löwis" martin at v.loewis.de
Tue Dec 2 00:10:57 CET 2008


Alex Martelli wrote:
> I wonder if there's some desiderata left for future Python versions to
> make this standard behavior easier (for C-coded, Python-coded, and
> Cython-coded classes, ones made by SWIG, etc) without too much black
> magic...

I think the standard exception hierarchy should grow additional standard
fields. E.g. AttributeError should have attributes 'type','name', or
perhaps even 'object','name'. TypeError should have attributes
'expected', 'actual' (or, again, 'expected', 'object'). Also, some
languages support nested exceptions (attribute 'inner'); usefulness of
this concept should be reviewed.

And so on - that might produce quite a large PEP. As 3.0 missed the
chance to fix this, compatibility is also an issue. It might be possible
to overload exception constructors on the number of parameters, or using
keyword parameters for the new way of filling the exception.

And no, I don't volunteer to write this PEP :-)

Regards,
Martin


More information about the Python-Dev mailing list