If we recall the class decorator we used in Chapter 5, Using Decorators to Improve Our Code, to determine how an event object is going to be serialized, we ended up with an implementation that (for Python 3.7+) relied on two class decorators:
@Serialization( username=show_original, password=hide_field, ip=show_original, timestamp=format_time,)@dataclassclass LoginEvent: username: str password: str ip: str timestamp: datetime
The first one takes the attributes from the annotations to declare the variables, whereas the second one defines how to treat each file. Let's see whether we can change these two decorators for descriptors instead.
The idea is to create a descriptor that will apply the transformation over the ...