doctest environment question

tag thomas.guest at gmail.com
Tue May 22 07:56:29 EDT 2007


On 22 May, 10:11, "Gabriel Genellina" <gagsl-... at yahoo.com.ar> wrote:
> The version given by Peter Otten may do what you want, but I'd consider if
> you really need an announce_function in the first place, given all the
> other ways you already have to do the same thing.
> Implicitely rebinding globals does not look good.

Thanks for the advice Gabriel. The use case I have is that I'd like to
be able to decorate classes and even modules in this way:

>>> import announce
>>> import spam
>>> announce.announce_module(spam)

Here, "announce.announce_module" has a look in "spam", finds all the
functions and instancemethods, and decorates them (rebinds them) by
announcing calls to these functions and instancemethods.

It's something I've found useful, though clearly the behaviour of
"spam" has been drastically changed. I'd appreciate advice on better
ways to achieve this kind of thing, or why it doesn't look good.






More information about the Python-list mailing list