[Python-ideas] socket module: plain stuples vs named tuples

Guido van Rossum guido at python.org
Mon Jun 19 17:58:50 EDT 2017


There are examples in timemodule.c which went through a similar conversion
from plain tuples to (sort-of) named tuples. I agree that upgrading the
tuples returned by the socket module to named tuples would be nice, but
it's a low priority project. Maybe someone interested can create a PR?
(First open an issue stating that you're interested; point to this email
from me to prevent that some other core dev just closes it again.)

On Mon, Jun 19, 2017 at 2:24 PM, Victor Stinner <victor.stinner at gmail.com>
wrote:

> Hi,
>
> 2017-06-13 22:13 GMT+02:00 Thomas Güttler <guettliml at thomas-guettler.de>:
> > AFAIK the socket module returns plain tuples in Python3:
> >
> >   https://docs.python.org/3/library/socket.html
> >
> > Why not use named tuples?
>
> For technical reasons: the socket module is mostly implemented in the
> C language, and define a "named tuple" in C requires to implement a
> "sequence" time which requires much more code than creating a tuple.
>
> In short, create a tuple is as simple as Py_BuildValue("OO", item1, item2).
>
> Creating a "sequence" type requires something like 50 lines of code,
> maybe more, I don't know exactly.
>
> Victor
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>



-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20170619/b4c4559e/attachment-0001.html>


More information about the Python-ideas mailing list