git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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?