Do not inherit from built-in "dict"

Bug #1849980 reported by Rodolfo Alonso
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
neutron
Fix Released
Low
Rodolfo Alonso

Bug Description

agent.linux.dhcp.DictModel inherits from built-in "dict" type. This is not recommended because some type methods are implemented not in Python but in C [1][2] and should not be overridden. Subclassing the built-in types directly, will yield non-obvious errors that are hard to debug, and identify at first glance [3].

[1] http://www.kr41.net/2016/03-23-dont_inherit_python_builtin_dict_type.html
[2] https://treyhunner.com/2019/04/why-you-shouldnt-inherit-from-list-and-dict-in-python/
[3] https://medium.com/bynder-tech/using-collections-in-python-36129737b5a1

Tags: refactoring
Changed in neutron:
assignee: nobody → Rodolfo Alonso (rodolfo-alonso-hernandez)
Revision history for this message
Lajos Katona (lajos-katona) wrote :

I set it low as this is not a user facing issue, but of course important to make the code base more robust.

Changed in neutron:
importance: Undecided → Low
status: New → Confirmed
tags: added: refactoring
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to neutron (master)

Fix proposed to branch: master
Review: https://review.opendev.org/691874

Changed in neutron:
status: Confirmed → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to neutron (master)

Reviewed: https://review.opendev.org/691874
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=4b3baeb15a8015e8ed9075e465cf97800189eef2
Submitter: Zuul
Branch: master

commit 4b3baeb15a8015e8ed9075e465cf97800189eef2
Author: Rodolfo Alonso Hernandez <email address hidden>
Date: Fri Oct 25 17:00:43 2019 +0000

    Do not inherit from built-in "dict"

    This is not recommended because some type methods are implemented not
    in Python but in C [1][2] and should not be overridden. Subclassing
    the built-in types directly, will yield non-obvious errors that are
    hard to debug, and identify at first glance [3].

    [1] http://www.kr41.net/2016/03-23-dont_inherit_python_builtin_dict_type.html
    [2] https://treyhunner.com/2019/04/why-you-shouldnt-inherit-from-list-and-dict-in-python/
    [3] https://medium.com/bynder-tech/using-collections-in-python-36129737b5a1

    Closes-Bug: #1849980

    Change-Id: I08c712ff1b093370cda2ce66b93e2a0709094fe1

Changed in neutron:
status: In Progress → Fix Released
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix included in openstack/neutron 16.0.0.0b1

This issue was fixed in the openstack/neutron 16.0.0.0b1 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.