[Python-Dev] Heads up: socket.connect() breakage ahead

Guido van Rossum guido@python.org
Fri, 24 Mar 2000 16:27:51 -0500


> >>>>> "GvR" == Guido van Rossum <guido@python.org> writes:
> 
>     GvR> Someone noticed that socket.connect() and a few related
>     GvR> functions (connect_ex() and bind()) take either a single
>     GvR> (host, port) tuple or two separate arguments, but that only
>     GvR> the tuple is documented.
> 
>     GvR> Similar to append(), I'd like to close this gap, and I've
>     GvR> made the necessary changes.  This will probably break lots of
>     GvR> code.
> 
> I don't agree that socket.connect() and friends need this fix.  Yes,
> obviously append() needed fixing because of the application of Tim's
> Twelfth Enlightenment to the semantic ambiguity.  But socket.connect()
> has no such ambiguity; you may spell it differently, but you know
> exactly what you mean.
> 
> My suggestion would be to not break any code, but extend connect's
> interface to allow an optional second argument.  Thus all of these
> calls would be legal:
> 
> sock.connect(addr)
> sock.connect(addr, port)
> sock.connect((addr, port))

You probably meant:

  sock.connect(addr)
  sock.connect(host, port)
  sock.connect((host, port))

since (host, port) is equivalent to (addr).

> One nit on the documentation of the socket module.  The second entry
> says:
> 
>     bind (address) 
> 	 Bind the socket to address. The socket must not already be
> 	 bound. (The format of address depends on the address family --
> 	 see above.)
> 
> Huh?  What "above" part should I see?  Note that I'm reading this doc
> off the web!

Fred typically directs latex2html to break all sections apart.  It's
in the previous section:

  Socket addresses are represented as a single string for the AF_UNIX
  address family and as a pair (host, port) for the AF_INET address
  family, where host is a string representing either a hostname in
  Internet domain notation like 'daring.cwi.nl' or an IP address like
  '100.50.200.5', and port is an integral port number. Other address
  families are currently not supported.  The address format required by
  a particular socket object is automatically selected based on the
  address family specified when the socket object was created.

This also explains the reason for requiring a single argument: when
using AF_UNIX, the second argument makes no sense!

Frankly, I'm not sure what do here -- it's more correct to require a
single address argument always, but it's more convenient to allow two
sometimes.

Note that sendto(data, addr) only accepts the tuple form: you cannot
write sendto(data, host, port).

--Guido van Rossum (home page: http://www.python.org/~guido/)