def generate_update_method()

in src/sagemaker_core/tools/resources_codegen.py [0:0]


    def generate_update_method(self, resource_name: str, **kwargs) -> str:
        """
        Auto-generate the UPDATE method for a resource.

        Args:
            resource_name (str): The resource name.

        Returns:
            str: The formatted Update Method template.

        """
        # Get the operation and shape for the 'update' method
        operation_name = "Update" + resource_name
        operation_metadata = self.operations[operation_name]
        operation_input_shape_name = operation_metadata["input"]["shape"]

        required_members = self.shapes[operation_input_shape_name]["required"]

        # Exclude any required attributes that are already present as resource attributes and are also identifiers
        exclude_required_attributes = []
        for member in required_members:
            snake_member = convert_to_snake_case(member)
            if snake_member in kwargs["resource_attributes"] and any(
                id in snake_member for id in ["name", "arn", "id"]
            ):
                exclude_required_attributes.append(snake_member)

        # Generate the arguments for the 'update' method
        update_args = self._generate_method_args(
            operation_input_shape_name, exclude_required_attributes
        )

        operation_input_args = self._generate_operation_input_necessary_args(
            operation_metadata, exclude_required_attributes
        )

        # Convert the resource name to snake case
        resource_lower = convert_to_snake_case(resource_name)

        # Convert the operation name to snake case
        operation = convert_to_snake_case(operation_name)

        docstring = self._generate_docstring(
            title=f"Update a {resource_name} resource",
            operation_name=operation_name,
            resource_name=resource_name,
            operation_input_shape_name=operation_input_shape_name,
            include_session_region=False,
            include_return_resource_docstring=True,
            exclude_resource_attrs=kwargs["resource_attributes"],
        )

        # Format the method using the CREATE_METHOD_TEMPLATE
        if kwargs["needs_defaults_decorator"]:
            formatted_method = UPDATE_METHOD_TEMPLATE.format(
                docstring=docstring,
                service_name="sagemaker",
                resource_name=resource_name,
                resource_lower=resource_lower,
                update_args=update_args,
                operation_input_args=operation_input_args,
                operation=operation,
            )
        else:
            formatted_method = UPDATE_METHOD_TEMPLATE_WITHOUT_DECORATOR.format(
                docstring=docstring,
                service_name="sagemaker",
                resource_name=resource_name,
                resource_lower=resource_lower,
                update_args=update_args,
                operation_input_args=operation_input_args,
                operation=operation,
            )

        # Return the formatted method
        return formatted_method