On Wed, 28 Jun 2000, Andrew Kuchling wrote: > You could imagine a Python implementation that added flag > bits to every object, and set a bit if there was a __getattr__ method > defined; code could then do 'if (obj->flags & GMAGICAL) ...' instead > of the more complicated 'if (PyObject_HasAttrString(obj, > "__getattr__")'. That looks like a reasonable sort of optimization to me, though as far as i can tell it looks like that optimization has already been done: in PyClass_New(bases, dict, name): [...] op->cl_getattr = class_lookup(op, getattrstr, &dummy); [...] in instance_getattr(inst, name): if (res == NULL && (func = inst->in_class->cl_getattr) != NULL) { [...special __getattr__ handling...] } In general, optimizations of the form "add a flag to avoid a frequent expensive test" seem okay to me, as long they are a demonstrable win and the flag can be given a clear, simple name. -- ?!ng "To be human is to continually change. Your desire to remain what you are is what ultimately limits you." -- The Puppet Master, Ghost in the Shell
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4