parameters: (ip: str)
return_statement: return True
docstring: Returns ``True`` if the given string is a well-formed IP address.
  
      Supports IPv4 and IPv6.
docstring_summary: Returns ``True`` if the given string is a well-formed IP address.
docstring_tokens: Returns True if the given string is a well - formed IP address .
function: def is_valid_ip(ip: str) -> bool:
      """Returns ``True`` if the given string is a well-formed IP address.
  
      Supports IPv4 and IPv6.
      """
      if not ip or "\x00" in ip:
          # getaddrinfo resolves empty strings to localhost, and truncates
          # on zero bytes.
          return False
      try:
          res = socket.getaddrinfo(
              ip, 0, socket.AF_UNSPEC, socket.SOCK_STREAM, 0, socket.AI_NUMERICHOST
          )
          return bool(res)
      except socket.gaierror as e:
          if e.args[0] == socket.EAI_NONAME:
              return False
          raise
      return True
function_tokens: def is_valid_ip ( ip : str ) -> bool : if not ip or "\x00" in ip : # getaddrinfo resolves empty strings to localhost, and truncates # on zero bytes. return False try : res = socket . getaddrinfo ( ip , 0 , socket . AF_UNSPEC , socket . SOCK_STREAM , 0 , socket . AI_NUMERICHOST ) return bool ( res ) except socket . gaierror as e : if e . args [ 0 ] == socket . EAI_NONAME : return False raise return True