|
You have a few issues here. Firstly there was an indentation error for the parent do_something definition. This meant that it was defined as a function in and of itself, rather than being a method of the class Parent. Secondly, class methods should usually have self as their first parameter, as when they are called, the object that they refer to is passed as the first variable. Thirdly, when you call super() you do not need to specify what the super is, as that is inherent in the class definition for Child. Below is a fixed version of your code which should perform as you expect. class Parent: def __init__(self): pass def do_something(self, some_parameter, next_parameter): if type(some_parameter) is not int: raise AttributeError("Some message") if type(next_parameter) is not int: raise AttributeError("Some message") class Child(Parent): def __init__(self): super(Parent).__init__() def do_something(self, some_parameter, next_parameter): super().do_something(some_parameter, next_parameter) return some_parameter + next_parameter test = Child() test.do_something(2, 2) (责任编辑:) |
