Skip to content

Inconsistent Mutability of Returned Objects: vcon.dialog vs vcon.parties #54

@slyapustin

Description

@slyapustin

There is an inconsistency in the mutability of objects returned by vcon.dialog and vcon.parties.

  • vcon.dialog returns 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 constructed Party objects from the underlying data, making in-place modifications ineffective since changes are not reflected in the internal vcon_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:

  1. Return references to mutable objects in both cases.
  2. Document clearly that parties returns 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", [])

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions