Any tools to print source code call hierarchy

Discussion in 'Python' started by Scott Chapman, Sep 6, 2003.

  1. I'm sure I'm not using the conventional names for this tool, more of a
    cross-referencer?. I couldn't find it on Google, I think for this reason.

    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
    Scott Chapman, Sep 6, 2003
    #1
    1. Advertising

  2. Scott Chapman <> wrote in message news:<>...
    > I'm sure I'm not using the conventional names for this tool, more of a
    > cross-referencer?. I couldn't find it on Google, I think for this reason.
    >
    > 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.


    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).
    Lothar Scholz, Sep 7, 2003
    #2
    1. Advertising

  3. Scott Chapman

    Simon Burton Guest

    On Sat, 06 Sep 2003 16:34:21 -0700, Lothar Scholz wrote:

    ....
    >
    > 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.
    Simon Burton, Sep 7, 2003
    #3
  4. "Simon Burton" <> schrieb im Newsbeitrag
    news:p...
    > On Sat, 06 Sep 2003 16:34:21 -0700, Lothar Scholz wrote:
    >
    > ...
    > >
    > > 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.


    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

    >
    > 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.
    >
    >
    >
    >
    Michael Peuser, Sep 7, 2003
    #4
  5. Simon Burton <> wrote in message news:<>...
    > 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.
    >


    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.
    Lothar Scholz, Sep 7, 2003
    #5
  6. On 7 Sep 2003 03:21:25 -0700, (Lothar Scholz) wrote:

    >Simon Burton <> wrote in message news:<>...
    >> 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.
    >>

    >
    >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
    Bengt Richter, Sep 7, 2003
    #6
  7. Scott Chapman

    John J. Lee Guest

    Scott Chapman <> writes:
    [...]
    > 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.


    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
    John J. Lee, Sep 8, 2003
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. manchi
    Replies:
    5
    Views:
    3,206
  2. Manfred Schneider
    Replies:
    6
    Views:
    3,158
    Manfred Schneider
    Dec 17, 2005
  3. Skip Montanaro
    Replies:
    1
    Views:
    529
  4. keto
    Replies:
    0
    Views:
    907
  5. David Cournapeau

    print a vs print '%s' % a vs print '%f' a

    David Cournapeau, Dec 30, 2008, in forum: Python
    Replies:
    0
    Views:
    337
    David Cournapeau
    Dec 30, 2008
Loading...

Share This Page