Skip to content

Cant Modify Immutable Attribute Error

cant_modify_immutable_attribute_error

Module for CantModifyImmutableAttributeError exception.

CantModifyImmutableAttributeError

Bases: Error[dict[str, object]]

Raised when there is an attempt to modify an immutable attribute of an object.

Source code in src/forging_blocks/foundation/errors/cant_modify_immutable_attribute_error.py
class CantModifyImmutableAttributeError(Error[dict[str, object]]):
    """Raised when there is an attempt to modify an immutable attribute of an object."""

    def __init__(self, class_name: str, attribute_name: str):
        """Initialise the error with the class and attribute that triggered the violation.

        Args:
            class_name: Name of the class whose immutable attribute was targeted.
            attribute_name: Name of the attribute that was being modified.
        """
        message = ErrorMessage(
            f"Cannot modify immutable attribute '{attribute_name}' of class '{class_name}'."
        )
        metadata = ErrorMetadata[dict[str, object]](
            {
                "class_name": class_name,
                "attribute_name": attribute_name,
            }
        )
        super().__init__(message, metadata)

__init__(class_name: str, attribute_name: str)

Initialise the error with the class and attribute that triggered the violation.

Parameters:

Name Type Description Default
class_name str

Name of the class whose immutable attribute was targeted.

required
attribute_name str

Name of the attribute that was being modified.

required
Source code in src/forging_blocks/foundation/errors/cant_modify_immutable_attribute_error.py
def __init__(self, class_name: str, attribute_name: str):
    """Initialise the error with the class and attribute that triggered the violation.

    Args:
        class_name: Name of the class whose immutable attribute was targeted.
        attribute_name: Name of the attribute that was being modified.
    """
    message = ErrorMessage(
        f"Cannot modify immutable attribute '{attribute_name}' of class '{class_name}'."
    )
    metadata = ErrorMetadata[dict[str, object]](
        {
            "class_name": class_name,
            "attribute_name": attribute_name,
        }
    )
    super().__init__(message, metadata)