[Python-Dev] special method lookup: how much do we care? (original) (raw)
Benjamin Peterson benjamin at python.org
Sat May 9 03:52:24 CEST 2009
- Previous message: [Python-Dev] special method lookup: how much do we care?
- Next message: [Python-Dev] special method lookup: how much do we care?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
2009/5/8 Terry Reedy <tjreedy at udel.edu>:
Benjamin Peterson wrote:
2009/5/8 Daniel Stutzbach <daniel at stutzbachenterprises.com>:
On Fri, May 8, 2009 at 6:14 PM, Benjamin Peterson <benjamin at 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 PyObjectGetattr. 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 lengthhint 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 LOADATTR 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 LOADATTR bytecode. Would a modified version of object.getattribute work?
No, it's easier to just use _PyObject_LookupSpecial there.
-- Regards, Benjamin
- Previous message: [Python-Dev] special method lookup: how much do we care?
- Next message: [Python-Dev] special method lookup: how much do we care?
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]