code: def build_validator_py(node: PlotlyNode):
      """
      Build validator class source code string for a datatype PlotlyNode
  
      Parameters
      ----------
      node : PlotlyNode
          The datatype node (node.is_datatype must evaluate to true) for which
          to build the validator class
      Returns
      -------
      str
          String containing source code for the validator class definition
      """
  
      # Validate inputs
      # ---------------
      assert node.is_datatype
  
      # Initialize source code buffer
      # -----------------------------
      buffer = StringIO()
  
      # Imports
      # -------
      # ### Import package of the validator's superclass ###
      import_str = ".".join(node.name_base_validator.split(".")[:-1])
      buffer.write(f"import {import_str }\n")
  
      # Build Validator
      # ---------------
      # ### Get dict of validator's constructor params ###
      params = node.get_validator_params()
  
      # ### Write class definition ###
      class_name = node.name_validator_class
      superclass_name = node.name_base_validator
      buffer.write(
          f"""
  
  class {class_name}({superclass_name}):
      def __init__(self, plotly_name={params['plotly_name']},
                         parent_name={params['parent_name']},
                         **kwargs):"""
      )
  
      # ### Write constructor ###
      buffer.write(
          f"""
          super({class_name}, self).__init__(plotly_name=plotly_name,
                           parent_name=parent_name"""
      )
  
      # Write out remaining constructor parameters
      for attr_name, attr_val in params.items():
          if attr_name in ["plotly_name", "parent_name"]:
              # plotly_name and parent_name are already handled
              continue
  
          buffer.write(
              f""",
                   {attr_name}=kwargs.pop('{attr_name}', {attr_val})"""
          )
  
      buffer.write(
          f""",
          **kwargs"""
      )
  
      buffer.write(")")
  
      # ### Return buffer's string ###
      return buffer.getvalue()
  
file_path: plotly.py/packages/python/plotly/codegen/validators.py
imports: import os.path
  from io import StringIO
  import _plotly_utils.basevalidators
  from codegen.utils import PlotlyNode, TraceNode, write_source_py
label_desc: Use image node_id 1 for calling a global function with example usage: build_validator_py(node) and returns: buffer