[Python-Dev] PEP 246, redux

Phillip J. Eby pje at telecommunity.com
Tue Jan 11 16:34:20 CET 2005


At 12:41 PM 1/11/05 +0000, Armin Rigo wrote:
>The point about tp_xxx slots is that when implemented in C with slots, you get
>the latter (correct) effect for free.  This is how metaconfusion is avoided in
>post-2.2 Python.  Using getattr() for that is essentially broken.  Trying to
>call the method and catching TypeErrors seems pretty fragile -- e.g. if you
>are calling a __conform__() which is implemented in C you won't get a Python
>frame in the traceback either.

An excellent point.  The issue hasn't come up before now, though, because 
there aren't any __conform__ methods written in C in the field that I know 
of.  Presumably, if there are any added to CPython in future, it will be 
because there's a tp_conform slot and it's needed for built-in types, in 
which case the problem is again moot for the implementation.

(FYI, C methods implemented in Pyrex add a dummy frame to the traceback 
such that you see the file and line number of the original Pyrex source 
code.  Very handy for debugging.)

Anyway, I agree that your version of the code should be used to form the 
reference implementation, since the purpose of the reference implementation 
is to show the complete required semantics.



More information about the Python-Dev mailing list