Ensure default arguments are not mutable

Bug #1530282 reported by javeme
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Sahara
Fix Released
Low
javeme

Bug Description

Python’s default arguments are evaluated once when the function is defined, not each time the function is called (like it is in say, Ruby). This means that if you use a mutable default argument and mutate it, you will and have mutated that object for all future calls to the function as well.

For more details, please refer to: http://docs.python-guide.org/en/latest/writing/gotchas/

Revision history for this message
Vitalii Gridnev (vgridnev) wrote :
Changed in sahara:
importance: Undecided → Low
assignee: nobody → javeme (javaloveme)
milestone: none → mitaka-2
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to sahara (master)

Reviewed: https://review.openstack.org/262208
Committed: https://git.openstack.org/cgit/openstack/sahara/commit/?id=3cb08bc52b365f2ad9971ae1df4993604158beea
Submitter: Jenkins
Branch: master

commit 3cb08bc52b365f2ad9971ae1df4993604158beea
Author: Javeme <email address hidden>
Date: Tue Dec 29 20:37:16 2015 +0800

    Ensure default arguments are not mutable

    * add hacking check: no_mutable_default_args()
    * remove the mutable default arguments "[]" or "{}" when the function
      is defined.

    ref: http://docs.python-guide.org/en/latest/writing/gotchas/

    Closes-Bug: #1530282
    Change-Id: Ice6f7654211b73d7f8bc3ca0e4dfae3dca354397

Changed in sahara:
status: In Progress → Fix Released
Revision history for this message
Thierry Carrez (ttx) wrote : Fix included in openstack/sahara 4.0.0.0b2

This issue was fixed in the openstack/sahara 4.0.0.0b2 development milestone.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.