bdb: which class?

Stuart Zakon zakons at objectsbydesign.com
Sun Jan 16 12:16:15 EST 2000


In article <20000112164417.4994.qmail at web805.mail.yahoo.com>,
  Stuart Zakon <sjz18 at yahoo.com> wrote:
>
> My gosh! I was afraid it was going to be that complicated!
> If I had any spare time I would look into why there couldn't just be
the
> following assignment to get the class:
>
> class_name = frame.f_code.co_class_name
>
> Then you could check to see if it was 'None' to indicate that the
method is not
> on a class but on a module.
>


# from the following it appears that the 'node' n contains the
# type information to give away the parent's identity as a classdef
# (versus a funcdef or a lambdef)
# all that is needed now is the name of the class to pass down to
# the PyCode_New function, which creates the code object.
# the result would be (co_name, co_classname, co_filename), more
# than enough to identify which method in a class is being called.
# is the name of the class readily available from the node??

# from jcompile() (compile.c, line 3409)

        compile_node(&sc, n);
        com_done(&sc);
        if ((TYPE(n) == funcdef || TYPE(n) == lambdef) &&
            sc.c_errors == 0) {
                optimize(&sc);
                sc.c_flags |= CO_NEWLOCALS;
        }
        else if (TYPE(n) == classdef)
                sc.c_flags |= CO_NEWLOCALS;

<snip, snip>

        co = PyCode_New(sc.c_argcount,
                         sc.c_nlocals,
                         sc.c_maxstacklevel,
                         sc.c_flags,
                         sc.c_code,
                         consts,
                         names,
                         varnames,
                         filename,
                         name,
                         sc.c_firstlineno,
                         sc.c_lnotab);



Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list