atcbosselut / python-progressbar

Automatically exported from code.google.com/p/python-progressbar
Other
0 stars 0 forks source link

ProgressBar __init__ function uses same default widget list for all instances #2

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Python 2.6.2 (r262:71600, Apr 18 2009, 06:27:57) 
[GCC 4.3.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from progressbar import *
>>> p1 = ProgressBar()
>>> print len(p1.widgets)
3
>>> p1.widgets.append(ETA())
>>> print len(p1.widgets)
4
>>> p2 = ProgressBar()
>>> print len(p2.widgets)
4

What is the expected output? What do you see instead?

I would expect that individual ProgressBar objects would not share widget
lists. I think the problem is that you are setting a default value for the
widgets list in the argument list of ProgressBar.__init__, and this ends up
passing the same widgets list instance to all ProgressBar objects.

See for example,

http://www.ferg.org/projects/python_gotchas.html#contents_item_6

What version of the product are you using? On what operating system?

version 2.2, from http://pypi.python.org/pypi/progressbar. This problem
should exist for all operating systems and all python versions.

Please provide any additional information below.

Original issue reported on code.google.com by joseph...@gmail.com on 9 Jun 2009 at 11:35

GoogleCodeExporter commented 9 years ago
I'm aware of this behavior. The widgets are not intended to be modified after 
the
ProgresBar object is created, instead they should always be passed as 
parameter. I
don't think making a read-only property is worth it, unless there's a greater 
reason
to do so.

Original comment by nilton.v...@gmail.com on 13 Jul 2009 at 10:48