4
Be the following class hierarchy, where class "A" has an abstract method called "foo":
# -*- coding: utf-8 -*-
import abc
class A:
__metaclass__ = abc.ABCMeta
def __init__(self):
pass
@abc.abstractmethod
def foo(self):
return
class B(A):
def __init__(self):
super(B, self).__init__()
pass
def foo(self):
print 'Foo method in class B'
class C(B):
def bar(self):
print 'Bar method in class C'
def main():
class_c = C()
class_c.foo()
class_c.bar()
if __name__ == "__main__":
main()
This code works perfectly by printing the following:
"Foo method in class B"
"Bar method in class C"
My doubt is that Pycharm says that class "C" should implement all abstract methods, in this case the methods defined in class "A".
Is there a convention that says I have to implement all abstract methods? Is there a problem with not implementing?
I can almost guarantee it’s bug Pycharm. C implements all methods of A. It’s just not so obvious.
– Maniero
"C" inherits from "B" which implements the abstract "foo" method of "A", yet has no problem?
– Michel Aquino
No. I think it is naive of the IDE. It is important to have the method implemented. Only if there is some trick in Python that I don’t know (so I didn’t answer) that creates some difficulty. But it shouldn’t exist.
– Maniero
Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?
– Maniero
I voted to close the question as non-reducible because it was clearly a problem in the IDE (or poor configuration) and cannot be reproduced only with the code snippet..
– Woss