[ python-Bugs-1661603 ] Misleading behavior for [] and {} default arguments

SourceForge.net noreply at sourceforge.net
Fri Feb 16 16:32:14 CET 2007


Bugs item #1661603, was opened at 2007-02-16 16:32
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1661603&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Parser/Compiler
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Matthijs (matthijsd)
Assigned to: Nobody/Anonymous (nobody)
Summary: Misleading behavior for [] and {} default arguments

Initial Comment:
Hello

On python 2.3.4 and 2.4.3, 

>>> def a(x=[]):
...   return x
... 
>>> y=a()
>>> y.append(1)
>>> a()
[1]

Hence, the default argument is not recomputed. The same behavior occurs with x={} instead of x=[].

This looks like a bug because it is not coherent with 

>>> def f():
...   return []
... 
>>> y=f()
>>> y.append(5)
>>> f()
[]

So, is it a feature?

Thanks



----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1661603&group_id=5470


More information about the Python-bugs-list mailing list