jangada.serialization.SerializableProperty.__set__#
- SerializableProperty.__set__(instance: object, value: Any) None#
Set the property value on an instance.
This method implements the descriptor set protocol. It handles default value resolution, parsing, write-once enforcement, observer notification, and post-initialization.
- Parameters:
- instanceobject
The instance on which to set the property.
- valueAny
The value to set. If None, the property is reset to its default.
- Raises:
- AttributeError
If the property is write-once and has already been set.
- Any exception raised by parser
Parser exceptions propagate to the caller.
Notes
The set operation follows this sequence: 1. Check if this is the first time being set 2. Enforce write-once constraint if applicable 3. If value is None, resolve to default (static or from callable) 4. Apply parser if present (to both defaults and explicit values) 5. Store the parsed value in instance.__dict__ 6. Call all observers with (instance, old_value, new_value) 7. If first set, call post-initializer if present
Setting to None always resets to the default value:
>>> class Example: ... value = SerializableProperty(default=10) ... >>> obj = Example() >>> obj.value = 50 >>> obj.value 50 >>> obj.value = None # Reset to default >>> obj.value 10
Write-once enforcement:
>>> class Config: ... setting = SerializableProperty(writeonce=True) ... >>> cfg = Config() >>> cfg.setting = "value1" >>> cfg.setting = "value2" # Raises AttributeError Traceback (most recent call last): ... AttributeError: setting is a write-once property and has already been set