jangada.serialization.SerializableProperty.postinitializer#
- SerializableProperty.postinitializer(func: Callable[[object], T]) Self#
Set a post-initialization function using decorator syntax.
The post-initializer is called once after the property is first set or accessed. It receives the instance as its only argument and runs after the value has been stored and observers have been called.
- Parameters:
- funcPostinitializer
Function to call after first initialization. Should accept one argument (the instance) and return None.
- Returns:
- Self
A new SerializableProperty instance with the initializer set.
Notes
This method creates a new descriptor instance rather than modifying the existing one, following the immutable descriptor pattern.
The post-initializer can safely: - Access the property value (it’s already set) - Modify the property value (won’t trigger another initialization) - Set up related properties or state - Perform expensive setup operations
Examples
>>> class DataLoader: ... data = SerializableProperty(default=None) ... ... @data.postinitializer ... def data(self): ... print("Initializing data...") ... if self.data is None: ... self.data = load_expensive_data() ... >>> loader = DataLoader() >>> # Post-initializer not yet called >>> _ = loader.data # First access triggers initialization Initializing data...