Deep Black Magic in Python: please help

Terry Reedy tjreedy at udel.edu
Fri Aug 13 15:26:13 EDT 2004


"Jan Burgy" <jburgy at hotmail.com> wrote in message
news:807692de.0408130310.6e3ed9db at posting.google.com...
>         return arg_dict["one"] + self.bar(arg_dict)

> It shouldn't be all that hard. My problem is the lookup of 'self.bar'. In
> the AST it looks something like
>
>     CallFunc(Getattr(Name('self'), 'bar'), [Name('arg_dict')], None,
None)
>
> How do I find the corresponding function?

The lookup returns a bound method, whose structure is an implementation
detail.

Completely untested suggestion, possibly not correct or possible:

Write an implementation-specific unwrap function.  Then either augment the
source code

.... + unwrap(self.bar)(self, arg_dict) # self now an explict arg

or the analysis code to do the unwrapping.  For the latter, recognize
Name('self') and replace the result of Getattr(Name('self'), 'bar') with
unwrap(thereof) and, again, augment the arg list.

Terry J. Reedy






More information about the Python-list mailing list