code: def hex2rgb(hexval: str, allow_short: bool = False) -> RGB:
      
      if not hexval:
          raise ValueError(
              'Expecting hex string (#RGB, #RRGGBB), got nothing: {!r}'.format(
                  hexval
              )
          )
      try:
          hexval = hexval.strip().lstrip('#')
      except AttributeError:
          raise ValueError(
              'Expecting hex string (#RGB, #RRGGBB), got: ({}) {!r}'.format(
                  type(hexval).__name__,
                  hexval
              )
          )
      if allow_short:
          hexval = fix_hex(hexval)
      if not len(hexval) == 6:
          raise ValueError(
              'Not a length 3 or 6 hex string (#RGB, #RRGGBB), got: {}'.format(
                  hexval
              )
          )
      try:
          val = tuple(
              int(''.join(hexval[i:i + 2]), 16)
              for i in range(0, len(hexval), 2)
          )
      except ValueError:
          # Bad hex string.
          raise ValueError('Invalid hex value: {}'.format(hexval))
      # Only needed to satisft typing. `return val` would work fine.
      r, g, b = val
      return r, g, b
docs: Return a tuple of (R, G, B) from a hex color.