On Tue, May 10, 2011 at 2:18 PM, Antonio Cuni <anto.c...@gmail.com> wrote:
> On 10/05/11 18:50, cool-RR wrote: > > Hey, > > > > It seems that in CPython a function gets a `.__module__` attribute > according > > to the current value of `__name__` when the function is being defined. In > Pypy > > this seems not to be working, since I changed `__name__` in globals (as > part > > of a test) but it still didn't change the function's `.__module__`. Is > this a > > deficiency in Pypy? > > could you please write the smallest possible test that shows the behavior? > > The source of the problem might be that pypy's Function object caches its > w_module attribute: so, if you get func.__module__ and *then* change > __name__, > the modification is not seen. > > Also, it seems that CPython sets the module name at function-definition > time, > while pypy does it only the first time that __module__ is actually got. So, > for example, the following code: > > def one(): pass > def two(): pass > print one.__module__, > __name__ = 'foo' > print two.__module__ > > prints '__main__ __main__' on cpython, and '__main__ foo' on pypy. > > Not sure whether it's a bug or an implementation detail. > > ciao, > Anto > Ah, then my problem is easily solved by accessing `my_function.__module__` before I change `__name__` back to its original value. I tested and it works. I can still make a test case if you have interest in it. Ram.
_______________________________________________ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev