code: def testFunctionParseErrors(self):
      # Non-function arguments.
      with self.assertRaisesRegex(
          ValueError, "Expected a typehint-annotated Python function"
      ):
          parse_typehint_component_function(object())
      with self.assertRaisesRegex(
          ValueError, "Expected a typehint-annotated Python function"
      ):
          parse_typehint_component_function("foo")
  
      # Unannotated lambda.
      with self.assertRaisesRegex(
          ValueError, "must have all arguments annotated with typehints"
      ):
          parse_typehint_component_function(lambda x: True)
  
      # Function with *args and **kwargs.
      with self.assertRaisesRegex(
          ValueError,
          "Return type annotation of @component func_a should be TypedDict or"
          " None.",
      ):
  
          def func_a(a: int, b: int) -> object:
              del a, b
              return object()
  
          parse_typehint_component_function(func_a)
  
      # Function with *args and **kwargs.
      with self.assertRaisesRegex(
          ValueError, r"does not support \*args or \*\*kwargs arguments"
      ):
  
          def func_b(
              a: int, b: int, *unused_args
          ) -> OutputDict(c=float):
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_b)
      with self.assertRaisesRegex(
          ValueError, r"does not support \*args or \*\*kwargs arguments"
      ):
  
          def func_c(
              a: int, b: int, **unused_kwargs
          ) -> OutputDict(c=float):
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_c)
  
      # Not all arguments annotated with typehints.
      with self.assertRaisesRegex(
          ValueError, "must have all arguments annotated with typehint"
      ):
  
          def func_d(a: int, b) -> OutputDict(c=float):
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_d)
  
      # Artifact type used in annotation without `InputArtifact[ArtifactType]` or
      # `OutputArtifact[ArtifactType]` wrapper.
      with self.assertRaisesRegex(
          ValueError,
          "Invalid type hint annotation.*"
          "should indicate whether it is used as an input or output artifact",
      ):
  
          def func_e(
              a: int, unused_b: standard_artifacts.Examples
          ) -> OutputDict(c=float):
              return {"c": float(a)}
  
          parse_typehint_component_function(func_e)
  
      # Invalid input typehint.
      with self.assertRaisesRegex(
          ValueError, "Unknown type hint annotation"
      ):
  
          def func_f(a: int, b: Dict[int, int]) -> OutputDict(c=float):
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_f)
  
      # Invalid output typehint.
      with self.assertRaisesRegex(
          ValueError, "Unknown type hint annotation"
      ):
  
          def func_g(a: int, b: int) -> OutputDict(c="whatever"):
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_g)
  
      # Invalid output typehint.
      with self.assertRaisesRegex(
          ValueError, "Unknown type hint annotation"
      ):
  
          def func_h(
              a: int, b: int
          ) -> OutputDict(c=Optional[standard_artifacts.Examples]):
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_h)
  
      # Output artifact in the wrong place.
      with self.assertRaisesRegex(
          ValueError,
          "output artifact 'c' should be declared as a function parameter",
      ):
  
          def func_i(
              a: int, b: int
          ) -> OutputDict(c=standard_artifacts.Examples):
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_i)
      with self.assertRaisesRegex(
          ValueError,
          "output artifact 'c' should be declared as a function parameter",
      ):
  
          def func_j(
              a: int, b: int
          ) -> OutputDict(
              c=OutputArtifact[standard_artifacts.Examples]
          ):
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_j)
  
      # Input artifact declared optional with non-`None` default value.
      with self.assertRaisesRegex(
          ValueError,
          "If an input artifact is declared as an optional argument, its default "
          "value must be `None`",
      ):
  
          def func_k(
              a: int,
              b: int,
              examples: InputArtifact[
                  standard_artifacts.Examples
              ] = 123,
          ) -> OutputDict(c=float):
              del examples
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_k)
  
      # Output artifact declared optional.
      with self.assertRaisesRegex(
          ValueError,
          "Output artifact of component function cannot be declared as optional",
      ):
  
          def func_l(
              a: int,
              b: int,
              model: OutputArtifact[standard_artifacts.Model] = None,
          ) -> OutputDict(c=float):
              del model
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_l)
  
      # Optional parameter's default value does not match declared type.
      with self.assertRaisesRegex(
          ValueError,
          "The default value for optional input value .* on function .* must be "
          "an instance of its declared type .* or `None`",
      ):
  
          def func_m(
              a: int, b: int, num_iterations: int = "abc"
          ) -> OutputDict(c=float):
              del num_iterations
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_m)
  
      # Optional parameter's default value does not match declared type.
      with self.assertRaisesRegex(
          ValueError,
          "The default value for optional parameter .* on function must be an "
          "instance of its declared type .* or `None`",
      ):
  
          def func_n(
              a: int, b: int, num_iterations: Parameter[int] = "abc"
          ) -> OutputDict(c=float):
              del num_iterations
              return {"c": float(a + b)}
  
          parse_typehint_component_function(func_n)
  
imports: from typing import Dict, List, Optional, TypedDict, Union
  import apache_beam
  import tensorflow
  from tfx.dsl.component.experimental.annotations import BeamComponentParameter
  from tfx.dsl.component.experimental.annotations import InputArtifact
  from tfx.dsl.component.experimental.annotations import OutputArtifact
  from tfx.dsl.component.experimental.annotations import OutputDict
  from tfx.dsl.component.experimental.annotations import Parameter
  from tfx.dsl.component.experimental.function_parser import parse_typehint_component_function
  from tfx.dsl.component.experimental.utils import ArgFormats
  from tfx.types import standard_artifacts
label_desc: Use image node_id 7 for calling the FunctionParserTest obj's underlying member method code with example usage: obj.testFunctionParseErrors() and returns: object, dict, dict, dict, dict, dict, dict, dict, dict, dict, dict, dict, dict, dict