On 09. 02. 22 20:04, Stefan Behnel wrote:
Guido van Rossum schrieb am 09.02.22 um 19:36:
On Wed, Feb 9, 2022 at 9:41 AM Pablo Galindo Salgado wrote:
On Wed, 9 Feb 2022 at 17:38, Stefan Behnel 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.

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).
 >
 > 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?

So, what we currently do is to update the line number (which IIRC is really the start line number of the current function) on the current frame when an exception is raised, and the byte code offset to 0. That's a hack but shows the correct code line in the traceback. Probably conflicts with pdb, but there are still other issues with that anyway.

So, should there be a mechanism to set source/lineno/position on tracebacks/exceptions, rather than always requiring a frame for it?


_______________________________________________
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/6AVY3W7PLUFAYQE26JEW3F5IUY2NBA6N/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to