On 30 ene, 12:00, Steven D'Aprano <[EMAIL PROTECTED] cybersource.com.au> wrote:
> I call that a bug in the inspect module. In fact, looking at the source > for the findsource() function, I can see no fewer than two bugs, just in > the way it handles classes: > > (1) it assumes that the only way to create a class is with a class > statement, which is wrong; and > > (2) it assumes that the first occurrence of "class <name>" must be the > correct definition, which is also wrong. Yes, it's broken. But I'm afraid that's the only available thing to do. Python stores filename and line number information in code objects (only). If you have a reference to any code object (a method, a function, a traceback...) inspect can use it to retrieve that information. Once a class is defined, there is no code object attached to it. (The class statement is executed when the module is loaded and initialized, but that code object is discarded afterwards because it's not required anymore). If you *know* that a certain method is defined in a class, you can use it to find the real module. But in general, there is nothing to start with. I'm eagerly waiting for someone to come and say I'm wrong... -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list