Pycharm offers only implementation of an abstract getter but not an abstract setter

zljubisic at gmail.com zljubisic at gmail.com
Thu Jun 25 02:02:31 EDT 2020


This also works with no errors:

from abc import ABC, abstractmethod

class C(ABC):
    
    @property
    @abstractmethod
    def my_abstract_property(self):
        pass

    @my_abstract_property.setter
    @abstractmethod
    def my_abstract_property(self, val):
        pass

class D(C):
    my_abstract_property = 1

if __name__ == '__main__':
    x = D()
    print(x.my_abstract_property)
    x.my_abstract_property = 5
    print(x.my_abstract_property)


Output:
1
5

I expected to get an error that setter is not implemented.
If I try to instante C class directly as: x = C(), I will get an error:
TypeError: Can't instantiate abstract class C with abstract methods my_abstract_property

Can someone please explain to me how it works i python?


More information about the Python-list mailing list