Python super() behavior not dependable

前端 未结 5 1738
逝去的感伤
逝去的感伤 2021-02-01 13:37

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          


        
5条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-01 14:28

    I'm not sure why the error is happening, but as an aid to debugging you could wrap the call to super in a try/except block and do a data dump when the exception is raised. Something like this:

    class Retrieval(DBConnection.DBAdminConnection): 
        def __init__(self, username=None, password=None, unique_key=None):
            try:
                super(Retrieval,self).__init__()
            except TypeError, e:
                print "Failure initialising Retrieval --> self: %r"
                raise
            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
    

提交回复
热议问题