← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1183698] Re: Use of [] as default in __init__ parameters

 

** Changed in: horizon
       Status: Fix Committed => Fix Released

** Changed in: horizon
    Milestone: None => icehouse-2

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to OpenStack Dashboard (Horizon).
https://bugs.launchpad.net/bugs/1183698

Title:
  Use of [] as default in __init__ parameters

Status in OpenStack Dashboard (Horizon):
  Fix Released

Bug description:
  The [] shouldn't be used as default in __init__ parameters

  e.g here 
  https://github.com/openstack/horizon/blob/master/horizon/tables/actions.py#L182
  https://github.com/openstack/horizon/blob/master/horizon/tables/actions.py#L273

  
  here is little example why not 
  http://pastebin.com/nRyRjhWu

  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

To manage notifications about this bug go to:
https://bugs.launchpad.net/horizon/+bug/1183698/+subscriptions