For some reason, the super()
method is not always behaving as expected, opting to return:
TypeError('super(type, obj): obj must be an instance or subtype of type)'
I understand what the error means. I do not understand why it is coming up as an error. Here's the snippet of code that is breaking. All objects in the system are new style objects.
What's really interesting is that this error does not always show up. I don't know what's causing it. The super()
method in Retrieval
is passing the Retrieval
class, and then itself as an object, which is, as far as I'm aware,exactly how super()
is supposed to be invoked.
Any thoughts at all?
In file DBConnection.py:
class DBAdminConnection(object): def __init__(self): self.user = DBUserConnection().user self.submissions = DBSubmissionConnection()
In file Retrieval.py
class Retrieval(DBConnection.DBAdminConnection): def __init__(self, username=None, password=None, unique_key=None): super(Retrieval,self).__init__() if username and password: self.username = username self.user.login(username,password, config.DATABASE) if self.user.error: raise UserLoginError(username) self.unique_key = unique_key
The super() function is used to give access to methods and properties of a parent or sibling class. The super() function returns an object that represents the parent class.
Yes, you should use super() over other methods. This is now the standard object inheritance model in Python 3.
When you initialize a child class in Python, you can call the super(). __init__() method. This initializes the parent class object into the child class. In addition to this, you can add child-specific information to the child object as well.
Use of super() In Python, super() has two major use cases: Allows us to avoid using the base class name explicitly. Working with Multiple Inheritance.
Are you reloading modules somehow in the middle of things? If so, that may explain this error.
isinstance(self,DBAdminConnection)
may become false after reloading modules because of the changes to memory references, apparently.
Edit: if you're running your web.py app under mod_wsgi, make sure you're disabling autoreload:
app = web.application(urls, globals(), autoreload=False)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With