-
Notifications
You must be signed in to change notification settings - Fork 6
Inconsistent Mutability of Returned Objects: vcon.dialog vs vcon.parties #54
Copy link
Copy link
Closed
Description
There is an inconsistency in the mutability of objects returned by vcon.dialog and vcon.parties.
vcon.dialogreturns a list of dictionaries from the internal data structure, allowing users to modify dialog entries in place.vcon.parties, on the other hand, returns newly constructedPartyobjects from the underlying data, making in-place modifications ineffective since changes are not reflected in the internalvcon_dict.
This inconsistency can be confusing for users. Either both properties should return mutable references that allow in-place updates, or neither should.
Proposed solutions:
- Return references to mutable objects in both cases.
- Document clearly that
partiesreturns copies and must be updated through specific methods.
Let me know your thoughts or if you'd prefer one approach over the other.
@property
def parties(self) -> List[Party]:
"""
Get the list of parties in the vCon.
Returns:
A list of Party objects representing all participants in the conversation
Example:
>>> vcon = Vcon.build_new()
>>> vcon.add_party(Party(type="person", name="John Doe"))
>>> parties = vcon.parties
>>> print(parties[0].name) # Prints "John Doe"
"""
return [Party(**party) for party in self.vcon_dict.get("parties", [])]
@property
def dialog(self) -> List[Dict[str, Any]]:
"""
Get the list of dialog entries in the vCon.
Returns:
A list of dialog entries representing the conversation content
Example:
>>> vcon = Vcon.build_new()
>>> vcon.add_dialog(Dialog(type="text", start="2023-01-01T00:00:00Z", parties=[0]))
>>> dialog = vcon.dialog
>>> print(dialog[0]["type"]) # Prints "text"
"""
return self.vcon_dict.get("dialog", [])Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels