<div dir="ltr"><div class="gmail_quote">On Tue, May 10, 2011 at 2:18 PM, Antonio Cuni <span dir="ltr">&lt;<a href="mailto:anto.cuni@gmail.com">anto.cuni@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
<div><div></div><div class="h5">On 10/05/11 18:50, cool-RR wrote:<br>
&gt; Hey,<br>
&gt;<br>
&gt; It seems that in CPython a function gets a `.__module__` attribute according<br>
&gt; to the current value of `__name__` when the function is being defined. In Pypy<br>
&gt; this seems not to be working, since I changed `__name__` in globals (as part<br>
&gt; of a test) but it still didn&#39;t change the function&#39;s `.__module__`. Is this a<br>
&gt; deficiency in Pypy?<br>
<br>
</div></div>could you please write the smallest possible test that shows the behavior?<br>
<br>
The source of the problem might be that pypy&#39;s Function object caches its<br>
w_module attribute: so, if you get func.__module__ and *then* change __name__,<br>
the modification is not seen.<br>
<br>
Also, it seems that CPython sets the module name at function-definition time,<br>
while pypy does it only the first time that __module__ is actually got. So,<br>
for example, the following code:<br>
<br>
def one(): pass<br>
def two(): pass<br>
print one.__module__,<br>
__name__ = &#39;foo&#39;<br>
print two.__module__<br>
<br>
prints &#39;__main__ __main__&#39; on cpython, and &#39;__main__ foo&#39; on pypy.<br>
<br>
Not sure whether it&#39;s a bug or an implementation detail.<br>
<br>
ciao,<br>
Anto<br>
</blockquote></div><br>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.<div><br></div><div>I can still make a test case if you have interest in it.</div>
<div><br></div><div><br></div><div>Ram.</div></div>