[ python-Bugs-1152726 ] Default class args get clobbered by prior instances.

2005-02-27 Thread SourceForge.net
Bugs item #1152726, was opened at 2005-02-26 22:10
Message generated for change (Comment added) made by rhettinger
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1152726group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Closed
Resolution: Invalid
Priority: 8
Submitted By: Simon Drabble (sdrabble)
Assigned to: Nobody/Anonymous (nobody)
Summary: Default class args get clobbered by prior instances.

Initial Comment:
OS: SuSE Linux 9.2  kernel 2.6.4
Python: 2.3.3

Define a class where the __init__() method takes a default arg of list 
type. Instantiate this class, and append/ extend the value of its default 
arg. Instantiate the class again, and the value from the first instance 
will overwrite the second. 

The bug is known to exist in 2.3.3, but may exist in subsequent 
releases also. 

The attached file illuminates the problem.

--

Comment By: Raymond Hettinger (rhettinger)
Date: 2005-02-27 08:18

Message:
Logged In: YES 
user_id=80475

Sorry, this is not a bug.  It is part of how Python works. 
In general, do not use mutables for default values. 
Instead, write something like:

def f(x, seq=None):
   if seq is None:
   seq = []
. . .

There is a FAQ on the subject:

http://www.python.org/doc/faq/general.html#why-are-default-values-shared-between-objects

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1152726group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1152726 ] Default class args get clobbered by prior instances.

2005-02-26 Thread SourceForge.net
Bugs item #1152726, was opened at 2005-02-26 22:10
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1152726group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Simon Drabble (sdrabble)
Assigned to: Nobody/Anonymous (nobody)
Summary: Default class args get clobbered by prior instances.

Initial Comment:
OS: SuSE Linux 9.2  kernel 2.6.4
Python: 2.3.3

Define a class where the __init__() method takes a default arg of list 
type. Instantiate this class, and append/ extend the value of its default 
arg. Instantiate the class again, and the value from the first instance 
will overwrite the second. 

The bug is known to exist in 2.3.3, but may exist in subsequent 
releases also. 

The attached file illuminates the problem.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1152726group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[ python-Bugs-1152726 ] Default class args get clobbered by prior instances.

2005-02-26 Thread SourceForge.net
Bugs item #1152726, was opened at 2005-02-26 22:10
Message generated for change (Settings changed) made by sdrabble
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1152726group_id=5470

Category: Python Interpreter Core
Group: Python 2.3
Status: Open
Resolution: None
Priority: 8
Submitted By: Simon Drabble (sdrabble)
Assigned to: Nobody/Anonymous (nobody)
Summary: Default class args get clobbered by prior instances.

Initial Comment:
OS: SuSE Linux 9.2  kernel 2.6.4
Python: 2.3.3

Define a class where the __init__() method takes a default arg of list 
type. Instantiate this class, and append/ extend the value of its default 
arg. Instantiate the class again, and the value from the first instance 
will overwrite the second. 

The bug is known to exist in 2.3.3, but may exist in subsequent 
releases also. 

The attached file illuminates the problem.

--

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detailatid=105470aid=1152726group_id=5470
___
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com