Bengt Richter wrote: ... > maybe there ought to be a magic __self__ in the local namespace of a function? > > Or better yet (?;-) if a user-defined function were a subclass of type function > instead of an instance, and a frame were an activation-instance of this function subclass, > then frame.__class__.__dict__ would be the function __dict__, where you could find attributes. I have similar thoughts, here, maybe simpler: A frame is something like an instance of a function, the function is somehow instantiated to be executed. Unfortunately, on creation of a frame, the function is "unpacked", in the sense that certain information is used to parameterize the frame, but then the frame has only the code object left. This is probably so, because frames are created in different context, like in the executable part of a class, or when the code of a script is run. There is no function, but there is a frame with a code object. Maybe it makes sense to just add the function/method to the code object as a new slot, which is either filled or set to None? I guess that not to do this was a decision from the pre-GC time, where this would have been a really bad circular reference? Then we could grow a frame attribute like __callable__ which grabs the callable from the code object. Maybe we should ask python-dev what they think.?