Python super() behavior not dependable

前端 未结 5 1744
逝去的感伤
逝去的感伤 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:15

    I had the same error then i noticed that i had duplicate class (my mistake) within the same file.py. Error disappeared when i renamed the second class A to class B

    #Just some example below, not real code
    class A (object):
    
        def fun(self):
            super(A, self).fun()
    
    class A (object): ##This second class with same name (A) caused the error
    
       def some_fun(self,x,y):
    

提交回复
热议问题