Deep Black Magic in Python: please help

Jan Burgy jburgy at
Mon Aug 16 09:04:41 CEST 2004

"Terry Reedy" <tjreedy at> wrote in message news:<mailman.1629.1092425178.5135.python-list at>...
> "Jan Burgy" <jburgy at> wrote in message
> news:807692de.0408130310.6e3ed9db at
> >         return arg_dict["one"] +
> > It shouldn't be all that hard. My problem is the lookup of ''. 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(, 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

Hi Terry,

Thank you very much for your suggestion. I am not sure how it would
help though. What is preventing me now from already replacing the
result of Getattr(Name('self'), 'bar') with what I need? That's
precisely my problem however. Because Python is a dynamically typed
language, I have no information about 'self' at compile-time. Short of
saving context information while I am visiting the parse tree, I don't
know how to tell what class I am in.

Would-Meta-Classes-help-me-in-this-case-ly yours?


More information about the Python-list mailing list