Ví dụ, tôi có một lớp cơ sở và lớp dẫn xuất:Một python @classmethod có thể được kế thừa không?
>>> class Base:
... @classmethod
... def myClassMethod(klass):
... pass
...
>>> class Derived:
... pass
...
>>> Base.myClassMethod()
>>> Derived.myClassMethod()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: class Derived has no attribute 'myClassMethod'
Có thể có lớp Derived có thể gọi myClassMethod mà không ghi đè lên nó và gọi phương thức lớp siêu không? Tôi muốn ghi đè lên phương thức lớp chỉ khi cần thiết.
lớp 'Derived' của bạn không có nguồn gốc từ' Base'. Nếu không, điều này sẽ làm việc. –