← Back to team overview

yahoo-eng-team team mailing list archive

[Bug 1657412] [NEW] L3_NAT_dbonly_mixin __new__ method has wrong signature

 

Public bug reported:

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)


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


  class Test(l3_db.L3_NAT_dbonly_mixin):

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

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

  Test(1)

** Affects: neutron
     Importance: Undecided
         Status: New

-- 
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:
  New

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)

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

  
    class Test(l3_db.L3_NAT_dbonly_mixin):

        @staticmethod
        def __new__(cls, *more):
            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


Follow ups