Things like os.stat_result use PyStructSequence_NewType, which is the C equivalent of a namedtuple. But a Struct Sequence has the extension of being able to have more named fields than the tuple length. It was designed, so I understand, just for cases like this. I don't know if it would be possible for you to use it from pure Python code, or maybe you'd need a C module to expose it.

There was idle talk many years ago of either extending namedtuple or creating some new type factory that could do the same from pure Python code, but no one ever got serious about it. I'm not sure it would be accepted in any event. Buy maybe if you have a concrete use case something like that could be done.

Eric

On 4/17/2022 1:20 PM, Pablo Galindo Salgado wrote:
Hi,

We are currently debating in gh-88116 (https://github.com/python/cpython/issues/88116) what's the best way forward to update the APIs in the inspect module to include the new position information.

These APIs are inspect.getframeinfo, inspect.getouterframes, inspect.getinnerframes, inspect.stack and inspect.trace.

The problem is that these APIs return a named tuple that now needs to include several new attributes (or one 4 tuple for the positions). Being named tuples, if we add a new attribute, existing unpackings of the tuple will now fail because there are more elements or the elements are in different positions. Also, it will be quite weird to add the new attributes at the
end but leave the line number at the beginning.

What's the best way to proceed here? The suggested way is to create a namedtuple subclass that adds the extra attributes but doesn't allow indexed access to it (there is a precedent to this in how we handled updating os.stat_result). I personally find this quite confusing but it certainly works. There may be other options.

What do you think?

Cheers from sunny London,
Pablo Galindo Salgado

_______________________________________________
Python-Dev mailing list --python-dev@python.org
To unsubscribe send an email topython-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived 
athttps://mail.python.org/archives/list/python-dev@python.org/message/RTGG637WWPOWUHUF6TRJYUSBYYSVUPRA/
Code of Conduct:http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at 
https://mail.python.org/archives/list/python-dev@python.org/message/JRVT7YZGXTWPJACWAOKR4EUPO6IZIBJQ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to