← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1657412] Re: L3_NAT_dbonly_mixin __new__ method has wrong signature

 

Reviewed:  https://review.openstack.org/422088
Committed: https://git.openstack.org/cgit/openstack/neutron/commit/?id=e862d280681bebecc590ce8853048287cb8d046a
Submitter: Zuul
Branch:    master

commit e862d280681bebecc590ce8853048287cb8d046a
Author: Aditya Reddy Nagaram <aditya_reddy.nagaram@xxxxxxxxxxxxxxxxx>
Date:   Thu Jan 19 15:40:09 2017 +0100

    Allow __new__  method to accept extra arguments
    
    L3_NAT_dbonly_mixin accepts no extra arguments, but
    some subclasses do want to be able to accept them.
    
    Change-Id: I069215c4f3031661b7ce2c692dcf4cce1bd29b6c
    Closes-bug: #1657412


** Changed in: neutron
       Status: In Progress => Fix Released

-- 
You received this bug notification because you are a member of Yahoo!
Engineering Team, which is subscribed to neutron.
https://bugs.launchpad.net/bugs/1657412

Title:
  L3_NAT_dbonly_mixin __new__ method has wrong signature

Status in neutron:
  Fix Released

Bug description:
  Since stable/newton, there is this code: https://github.com/openstack/neutron/blob/stable/newton/neutron/db/l3_db.py#L173
  master link: https://github.com/openstack/neutron/blob/master/neutron/db/l3_db.py#L95

  Python doc says: https://docs.python.org/2/reference/datamodel.html#object.__new__
  "...that takes the class of which an instance was requested as its first argument. The remaining arguments are those passed to the object constructor expression..."

  Because the __new__ method is overridden in L3_NAT_dbonly_mixin
  without accepting extra arguments. This forces all subclasses to have
  either no arguments to the __init__ method, or they have to override
  __new__ themselves to workaround this.

  The following code fails to run:
    from neutron.db import l3_db

    class Test(l3_db.L3_NAT_dbonly_mixin):

        def __init__(self, arg1):
            super(Test, self).__init__()
            self.arg1 = arg1

    Test(1)

  --TypeError: __new__() takes exactly 1 argument (2 given)

  The, hacky imo, workaround:
    from neutron.db import l3_db

    class Test(l3_db.L3_NAT_dbonly_mixin):

        @staticmethod
        def __new__(cls, *args, **kwargs):
            return super(Test, cls).__new__(cls)

        def __init__(self, arg1):
            super(Test, self).__init__()
            self.arg1 = arg1

    Test(1)

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


References