[Python-Dev] PEP: source proposal (original) (raw)

Stelios Xanthakis sxanth at ceid.upatras.gr
Fri Dec 3 22:59:30 CET 2004


On Fri, 3 Dec 2004, holger krekel wrote:

... there is another possibility for storing "source" or any other such meta information with code/module objects: make file and cofilename instances of a subclass of 'str' providing an extra attribute. For a simple example, they could have a 'source' attribute, which could be tried first by appropriate inspect functions and traceback related functionality.

Attaching such info on 'code objects' is indeed a more general case. But, OTOH, AFAIK, a class is not a code object. At least by what I was able to figure out from python sources.

It seems reasonable to make 'source' a dynamic object which will get its info from file/line if available. Now the thing is that if we had source from the start, 'inspect' would have been much different. So the fact that we have some functionality with inspect does not mean that it's good enough. Probably inspect will be rewritten/improved if source is implemented.

We are about to test out this approach with the py lib (http://codespeak.net/py) and want to have it work for for Python 2.2, 2.3. and 2.4.

Do you plan hacking python ? It appears that tok_nextc() is the best place to catch all the source passed to the interpreter.

A patch would be interesting.

Stelios



More information about the Python-Dev mailing list