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

Victor Stinner victor.stinner at gmail.com
Mon Jun 19 17:24:22 EDT 2017


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.


More information about the Python-ideas mailing list