I need a tool that will go through a python module (ClientForm in this case)
and allow me to specify a starting module to parse and tell me what all it
uses.
What I'm trying to do is to take ClientForm apart enough to pull out just the
html form parsing code in it and use it elsewhere. It would be MUCH easier
when approaching someone elses code if I could see what all functions are
called by a given function, etc.
TIA,
Scott
Because python is a dynamical typed non image language there is no
tool that can do this and there never will be any (at least one that
is not using heuristics or sampled data from previous runs).
...
>
> Because python is a dynamical typed non image language there is no
> tool that can do this and there never will be any (at least one that
> is not using heuristics or sampled data from previous runs).
hmmm... I think (some) static analysis may be possible. The main
thing to exclude is eval/exec but even then, yes you're right, some
programs would just have to be run to find out what they do.
I remember reading some interesting things here:
http://www.python.org/doc/essays/cp4e.html
In particular:
"Cormac Flanagan and Matthias Felleisen.
Componential Set-Based Analysis.
ACM Transactions of Programming Languages and Systems"
Simon.
It it is not only eval/exec. You can create methods dynamically. And static
analysis will already run into trouble when you import moduls dynamically.
What I do very often is "rename" a procedure, e.g. in cases as:
def pVersion1(): ...
def pVersion2(): ...
if....
p=pVersion1
This is not even tricky.
Kindly
Michael P
Whats with code like:
if foo:
def myfunc():
... do something
else:
def myfunc():
... calling your_func()
A Language where the program calling hierarchie depends on runtime
calculations is not able to provide good refactoring tools or static
flow analysis. This is the huge difference to a language like
Smalltalk where we live in an image.
And if you say that this is a hack, then you are making a big mistake,
look at currently used code and you will find so much uses of this
style (or even worse styles) that it seems to be a common paradigm.
Which only begins to hint at what is possible with metaclasses ;-)
Regards,
Bengt Richter
This is not a trivial exercise to perform with Python because it is
dynamically typed. In many cases you don't know the type of an object until
runtime.
Skip
In the absence of that, you could try just asking me. :-)
_FormParser is it, really. What exactly did you want to do?
As for the general question: I only glanced at the other replies, but
have you tried etags? Or for something in a single source file, as in
this case, why not just incremental search or other simple editor
commands? It's true a bit of knowledge of common dynamic Python
idioms is valuable here, though.
John
I wrote a tool called PySpy (see
http://members.rogers.com/qwavel/pyspy/) that presented call graph
information based on a runtime analysis of Python programs.
Unfortunately, it only works with Python v2.1. I hope to update it
when I get time.
I don't monitor this ng.
Tom.