Use of [] as default in __init__ parameters
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
OpenStack Dashboard (Horizon) |
Fix Released
|
Wishlist
|
Ladislav Smola |
Bug Description
The [] shouldn't be used as default in __init__ parameters
e.g here
https:/
https:/
here is little example why not
http://
the [] in the parameters creates object when the code is interpreted(when the instance of class is created). So then there is one object of array(list) for all objects that are created from that class
If my understanding of python is right, this applies not only for [] but for everything like tuples, strings.. (cause everything is object in python)
It is fine as long as you assign to the object attribute (because it creates new object). But any operation on the existing object, changes the one shared object (like append in the example).
This could lead to some pretty hard to find bugs.
The right way is to assign None and assign the [] in the __init__ body if the value is None
Changed in horizon: | |
importance: | Undecided → Wishlist |
Changed in horizon: | |
milestone: | none → icehouse-2 |
status: | Fix Committed → Fix Released |
Changed in horizon: | |
milestone: | icehouse-2 → 2014.1 |
this could be solved by https:/ /bugs.launchpad .net/horizon/ +bug/1182931
because there will be no default parameters of __init__ then
Every object attribute is set in the __init__ body
(it would be fixed for Horizon Actions at least)