Why are functions atomic?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed May 2 03:09:08 EDT 2007


En Wed, 02 May 2007 01:42:17 -0300, Martin v. Löwis <martin at v.loewis.de>  
escribió:

> Michael schrieb:
>> A bit more info, but still no clear picture about why functions are
>> mutable but have immutable copy symantics.  There are arguments why
>> functions should be immutable, but the decision was to make user-
>> defined functions mutable.  My question is still: why the present
>> ummutable copy symantics?
>
> The answer is really really simple. The implementation of copy predates
> mutability. When the copy code was written, functions *were* immutable.
> When functions became mutable, the copy code was not changed, and
> nobody noticed or complained.

Likely scenario, but not true. Support for copying user functions was  
added on 2.5 (see  
http://svn.python.org/view/python/trunk/Lib/copy.py?rev=42573&r1=38995&r2=42573)  
and functions were mutable since a long time ago. On previous versions,  
functions could be pickled but not copied.
The same thing happens for classes: they are mutable too, but copy  
considers them immutable and returns the same object. This is clearly  
stated on the documentation (but the module docstring is still outdated).

-- 
Gabriel Genellina



More information about the Python-list mailing list