[Python-ideas] socket module: plain stuples vs named tuples
ncoghlan at gmail.com
Mon Jun 19 23:04:45 EDT 2017
On 20 June 2017 at 12:05, INADA Naoki <songofacandy at gmail.com> wrote:
> Namedtuple in Python make startup time slow.
> So I'm very conservative to convert tuple to namedtuple in Python.
Aye, I don't think a Python level wrapper would be the right way to go
here - while namedtuple is designed to be as cheap as normal tuples in
*use*, the same can't be said for the impact on startup time.
As context for anyone not familiar with the time module precedent that
Guido mentioned, we have a C level `PyStructSequence` that provides
some of the most essential namedtuple features, but not all of them:
So there's potentially a case to be made for:
1. Including the struct sequence header from "Python.h" and making it
part of the stable ABI
2. Documenting it in the C API reference
The main argument against doing so is that the initialisation API for
it is pretty weird by the standards of the rest of the Python C API -
it's mainly designed for use as a C level type *factory*, rather than
intended to be used directly. That's also why there isn't a Python
level API for it - it's designed around accepting C level structs as
inputs, which doesn't translate well to pure Python code (whereas the
collections.namedtuple API works well in pure Python code, but doesn't
translate well to C code).
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
More information about the Python-ideas