Eliminate default value as a mutable object

Bug #1471349 reported by hongbin
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Magnum
Fix Released
Undecided
Unassigned
OpenStack Dashboard (Horizon)
Fix Released
Wishlist
Timur Sufiev

Bug Description

The default value is evaluated only once. This makes a difference when the default is a mutable object such as a list, dictionary, or instances of most classes. Magnum should follow what Python suggests: Do not to use mutable object as a default value.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to magnum (master)

Reviewed: https://review.openstack.org/198465
Committed: https://git.openstack.org/cgit/openstack/magnum/commit/?id=0b9b7de79ab96181e7ce89d0dd4cf3e183aff9de
Submitter: Jenkins
Branch: master

commit 0b9b7de79ab96181e7ce89d0dd4cf3e183aff9de
Author: Hongbin Lu <email address hidden>
Date: Fri Jul 3 18:09:28 2015 -0400

    Eliminate mutable default arguments

    The best practice in Python is not to use mutable object (i.e. list,
    dictionary, or instances of most classes) as value of default argument.

    See: https://docs.python.org/2/tutorial/controlflow.html#default-argument-values

    This patch also added a hacking rule to enforce this practice.

    Change-Id: I4aa8aede57d6fd31b4b30c3f7535b819e591165d
    Closes-Bug: 1471349

Changed in magnum:
status: New → Fix Committed
Revision history for this message
Timur Sufiev (tsufiev-x) wrote :

I find this check highly valuable and think it could be generalized for other OpenStack projects as well. Particularly, for Horizon.

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to horizon (master)

Fix proposed to branch: master
Review: https://review.openstack.org/225613

Changed in horizon:
assignee: nobody → Timur Sufiev (tsufiev-x)
status: New → In Progress
Changed in horizon:
assignee: Timur Sufiev (tsufiev-x) → Richard Jones (r1chardj0n3s)
Timur Sufiev (tsufiev-x)
Changed in horizon:
assignee: Richard Jones (r1chardj0n3s) → Timur Sufiev (tsufiev-x)
Adrian Otto (aotto)
Changed in magnum:
milestone: none → mitaka-1
status: Fix Committed → Fix Released
Timur Sufiev (tsufiev-x)
Changed in horizon:
importance: Undecided → Wishlist
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to horizon (master)

Reviewed: https://review.openstack.org/225613
Committed: https://git.openstack.org/cgit/openstack/horizon/commit/?id=7023050eddc9b2361bd200309329e4e6bf89709d
Submitter: Jenkins
Branch: master

commit 7023050eddc9b2361bd200309329e4e6bf89709d
Author: Timur Sufiev <email address hidden>
Date: Mon Sep 21 13:22:59 2015 +0300

    Eliminate mutable default arguments

    The best practice in Python is not to use mutable object (i.e. list,
    dictionary, or instances of most classes) as value of default
    argument (see https://goo.gl/Kwhg0T). A hacking rule to enforce this
    practice is added as well.

    The patch was inspired by CR https://review.openstack.org/#/c/198465/
    and took most of its code from it as well. That's why original
    copyrights are kept.

    Closes-Bug: #1471349
    Change-Id: Ia77b1736dbc3d4e28ff2d2c3424e9cfcaefa5077

Changed in horizon:
status: In Progress → Fix Released
Revision history for this message
Doug Hellmann (doug-hellmann) wrote : Fix included in openstack/horizon 9.0.0.0b2

This issue was fixed in the openstack/horizon 9.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.