code: def refine_sign(expr, assumptions):
      """
      Handler for sign.
  
      Examples
      ========
  
      >>> from sympy.assumptions.refine import refine_sign
      >>> from sympy import Symbol, Q, sign, im
      >>> x = Symbol('x', real = True)
      >>> expr = sign(x)
      >>> refine_sign(expr, Q.positive(x) & Q.nonzero(x))
      1
      >>> refine_sign(expr, Q.negative(x) & Q.nonzero(x))
      -1
      >>> refine_sign(expr, Q.zero(x))
      0
      >>> y = Symbol('y', imaginary = True)
      >>> expr = sign(y)
      >>> refine_sign(expr, Q.positive(im(y)))
      I
      >>> refine_sign(expr, Q.negative(im(y)))
      -I
      """
      arg = expr.args[0]
      if ask(Q.zero(arg), assumptions):
          return S.Zero
      if ask(Q.real(arg)):
          if ask(Q.positive(arg), assumptions):
              return S.One
          if ask(Q.negative(arg), assumptions):
              return S.NegativeOne
      if ask(Q.imaginary(arg)):
          arg_re, arg_im = arg.as_real_imag()
          if ask(Q.positive(arg_im), assumptions):
              return S.ImaginaryUnit
          if ask(Q.negative(arg_im), assumptions):
              return -S.ImaginaryUnit
      return expr
  
file_path: sympy/sympy/assumptions/refine.py
imports: from __future__ import annotations
  from typing import Callable
  from sympy.core import S, Add, Expr, Basic, Mul, Pow, Rational
  from sympy.core.logic import fuzzy_not
  from sympy.logic.boolalg import Boolean
  from sympy.assumptions import ask, Q
label_desc: Use image node_id 9 for calling a global function with example usage: refine_sign(expr, assumptions) and returns: expr, S, S, S, S, unknown