Benjamin Peterson wrote:
2009/5/8 Daniel Stutzbach <dan...@stutzbachenterprises.com>:
On Fri, May 8, 2009 at 6:14 PM, Benjamin Peterson <benja...@python.org>
wrote:
Normally special methods use slots of the PyTypeObject struct.
typeobject.c looks up all those methods on Python classes correctly.
In the case of __enter__ and __exit__, the compiler generates bytecode
to look them up, and that bytecode use PyObject_Getattr.
Would this problem apply to all special methods that don't use a slot in
PyTypeObject, then?  I know of several other examples:

Yes. I didn't think of those.

__reduce__
__setstate__
__reversed__
__length_hint__
__sizeof__

(unless I misunderstand the definition of "special methods", which is
possible)

__reversed__, at least, is called by the reversed() builtin, so there is no LOAD_ATTR k (__reversed__) byte code. So for that, the problem is reduced to accessing type(it).__reversed__ without going thru type(it).__getattribute__. I would think that a function that did that would work for the others on the list (all 4?) that also have no LOAD_ATTR bytecode. Would a modified version of object.__getattribute__ work?

tjr

_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to