[pypy-dev] Functions `.__module__` attribute
Antonio Cuni
anto.cuni at gmail.com
Tue May 10 20:18:23 CEST 2011
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
More information about the pypy-dev
mailing list