[Python-ideas] accurate errors for "magic" methods

Nick Coghlan ncoghlan at gmail.com
Fri Apr 10 04:04:50 CEST 2009


Benjamin Peterson wrote:
> Chris Rebert <pyideas at ...> writes:
>> And if PEP 3134 (http://www.python.org/dev/peps/pep-3134/) were
>> accepted+implemented, this could be made even clearer by using
>> exception chaining to indicate that the TypeError was caused (at least
>> semantically, disregarding optimizations) by the AttributeError.
> 
> And the time machine hits again! PEP 3134 has been implemented in Py3k.

Not quite - I'm pretty sure 3134 only kicks in reliably if an exception
makes it back into a Python exception handler. For C code, it isn't
necessarily the case that __cause__ and __context__ will be hooked up
automatically (and in the specific case of TypeErrors coming from
abstract.c, there is never an AttributeError in the first place - the
lookup code is checking specific slots on the type object rather than
doing a normal attribute lookup).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------



More information about the Python-ideas mailing list