bug or feature?

Steve Holden steve at holdenweb.com
Wed Oct 5 09:15:18 EDT 2005


Ben Sizer wrote:
> Fredrik Lundh wrote:
> 
> 
>>it's also mentioned in chapter 4 of the tutorial:
>>
>>    http://docs.python.org/tut/node6.html#SECTION006710000000000000000
>>
>>     "*Important warning*: The default value is evaluated only once. This
>>    makes a difference when the default is a mutable object such as a list,
>>    dictionary, or instances of most classes. "
> 
> 
> Perhaps it would be a good idea if Python actually raised a warning
> (SyntaxWarning?) if you use an unnamed list or dict as a default
> argument. This would doubtless help quite a few beginners. And for
> people who really do want that behaviour, working around the warning
> should involve minimal extra code, with extra clarity thrown in for
> free.
> 
This would have to be extended to any mutable object. How does the 
compiler know which objects are mutable?

This would not be a good change.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC                     www.holdenweb.com
PyCon TX 2006                  www.python.org/pycon/




More information about the Python-list mailing list