code: def attach(object: typing.Any, /, name: str) -> typing.Callable:
      """Return a decorator doing ``setattr(object, name)`` with its argument.
  
      >>> spam = type('Spam', (object,), {})()  # doctest: +NO_EXE
  
      >>> @attach(spam, 'eggs')
      ... def func():
      ...     pass
  
      >>> spam.eggs  # doctest: +ELLIPSIS
      <function func at 0x...>
      """
  
      def decorator(func):
          setattr(object, name, func)
          return func
  
      return decorator
  
file_path: graphviz/graphviz/_tools.py
imports: import functools
  import inspect
  import itertools
  import logging
  import os
  import pathlib
  import typing
  import warnings
label_desc: Use image node_id 1 for calling a global function with example usage: attach(name) and returns: decorator, func