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?
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to