code: def test_args_typed(self):
      args_dict = {"message": "hiya", "num_replicas": "3"}
  
      def build(args):
          """Builder with no type hint."""
  
          return self.A.options(num_replicas=args["num_replicas"]).bind(
              args["message"]
          )
  
      app = call_app_builder_with_args_if_necessary(build, args_dict)
      assert isinstance(app, Application)
  
      def build(args: Dict[str, str]):
          """Builder with vanilla type hint."""
  
          return self.A.options(num_replicas=args["num_replicas"]).bind(
              args["message"]
          )
  
      app = call_app_builder_with_args_if_necessary(build, args_dict)
      assert isinstance(app, Application)
  
      class ForwardRef:
          def build(args: "ForwardRef"):
              """Builder with forward reference as type hint."""
  
              return self.A.options(
                  num_replicas=args["num_replicas"]
              ).bind(args["message"])
  
      app = call_app_builder_with_args_if_necessary(
          ForwardRef.build, args_dict
      )
      assert isinstance(app, Application)
  
      def build(args: self.TypedArgs):
          """Builder with Pydantic model type hint."""
  
          assert isinstance(args, self.TypedArgs)
          assert args.message == "hiya"
          assert args.num_replicas == 3
          return self.A.options(num_replicas=args.num_replicas).bind(
              args.message
          )
  
      app = call_app_builder_with_args_if_necessary(build, args_dict)
      assert isinstance(app, Application)
  
      # Sanity check that pydantic validation works.
  
      # 1) Check that validation permits a missing optional field.
      def check_missing_optional(args: self.TypedArgs):
          assert args.message == "hiya"
          assert args.num_replicas is None
          return self.A.bind()
  
      app = call_app_builder_with_args_if_necessary(
          check_missing_optional, {"message": "hiya"}
      )
      assert isinstance(app, Application)
  
      # 2) Check that validation rejects a missing required field.
      def check_missing_required(args: self.TypedArgs):
          assert False, "Shouldn't get here because validation failed."
  
      with pytest.raises(ValidationError, match="field required"):
          call_app_builder_with_args_if_necessary(
              check_missing_required, {"num_replicas": "10"}
          )
  
imports: import asyncio
  import os
  import sys
  from typing import Dict, Optional
  import pytest
  import requests
  import starlette.responses
  from fastapi import FastAPI
  import ray
  from ray import serve
  from ray._private.pydantic_compat import BaseModel, ValidationError
  from ray._private.test_utils import SignalActor, wait_for_condition
  from ray.serve._private.api import call_app_builder_with_args_if_necessary
  from ray.serve._private.common import DeploymentID
  from ray.serve._private.constants import SERVE_DEFAULT_APP_NAME
  from ray.serve.deployment import Application
  from ray.serve.exceptions import RayServeException
  from ray.serve.handle import DeploymentHandle, RayServeHandle
label_desc: Use image node_id 8 for calling the TestAppBuilder obj's underlying member method code with example usage: obj.test_args_typed() and returns: self, self, self, self, self