Code: Select all
from dataclasses import dataclass, field
import numpy as np
class A():
a = np.arange(2)
class Verbose_attribute(A):
def __get__(self, obj, type=None) -> object:
print("accessing the attribute to get the value")
return self.a[-1]
def __set__(self, obj, value) -> None:
print("accessing the attribute to set the value")
self.a[-1]=value
#a = np.arange(2)
@dataclass
class Foo():
attribute1: Verbose_attribute = Verbose_attribute()
#attribute1: Verbose_attribute = field(default_factory=lambda: Verbose_attribute())
my_foo_object = Foo()
print(my_foo_object.attribute1)
my_foo_object.attribute1 = 3
print(my_foo_object.attribute1)