It might require a detailed API design proposal coming from outside CPython (e.g. from Cython) to get this to change. I imagine for co_positions in particular this would have to use a "builder" pattern.

I am unclear on how this would work though, given that Cython generates C code, not CPython bytecode. How would the synthesized co_positions be used? Would Cython just generate a co_positions fragment at the moment an exception is raised, pointing at the .pyx file from which the code was generated?

On Wed, Feb 9, 2022 at 9:41 AM Pablo Galindo Salgado <pablogsal@gmail.com> wrote:
I can only say that currently, I am not confident to expose such an API,
at least for co_positions, as the internal implementation is very likely to
heavily change and we want to have the possibility of changing it between
patch versions if required (to address bugs and other things like that).

On Wed, 9 Feb 2022 at 17:38, Stefan Behnel <stefan_ml@behnel.de> wrote:
Pablo Galindo Salgado schrieb am 09.02.22 um 17:40:
>> Should there be a getter/setter for co_positions?
>
> We consider the representation of co_postions private

Yes, and that's the issue.


> so we don't want (for now) to ad
> getters/setters. If you want to get the position of a instruction, you can
> use PyCode_Addr2Location

What Cython needs is the other direction. How can we provide the current
source position range for a given piece of code to an exception?

As it stands, the way to do this is to copy the implementation details of
CPython into Cython in order to let it expose the specific data structures
that CPython uses for its internal representation of code positions.

I would prefer using an API instead that allows exposing this mapping
directly to CPython's traceback handling, rather than having to emulate
byte code positions. While that would probably be quite doable, it's far
from a nice interface for something that is not based on byte code.

And that's not just a Cython issue. The same applies to Domain Specific
Languages or other programming languages that integrate with Python and
want to show users code positions for their source code.

Stefan

_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@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/VQSWX6MFKIA3RYPSX7O6RTVC422LTJH4/
Code of Conduct: http://python.org/psf/codeofconduct/
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-leave@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/P7SMK5ZGFAHZMLUKW4WZNNX47CONXIQS/
Code of Conduct: http://python.org/psf/codeofconduct/


--
--Guido van Rossum (python.org/~guido)
Pronouns: he/him (why is my pronoun here?)