[Python-ideas] Access to function objects

Antoine Pitrou solipsis at pitrou.net
Sun Aug 7 21:35:47 CEST 2011


On Sun, 7 Aug 2011 09:07:02 -0400
Guido van Rossum <guido at python.org> wrote:
> >
> > While this may sound a little hypocritical coming from the author of
> > PEPs 366 and 395, I'm wary of adding new implicit module globals for
> > problems with relatively simple and robust alternatives. In this case,
> > it's fairly easy to get access to the current module using the idiom
> > Guido quoted:
> >
> >    import sys
> >    _this = sys.modules[__name__]
> >
> > (or using dict-style access on globals())
> 
> Yeah, well, in most cases I find having to reference sys.modules a
> distraction and an unwarranted jump into the implementation. It may
> not even work: there are some recipes that replace
> sys.modules[__name__] with some wrapper object. If __this_module__
> existed it would of course refer to the "real" module object involved.

I would also add a ton of reference cycles and might create new juicy
problems in the module shutdown procedure :)

Regards

Antoine.





More information about the Python-ideas mailing list