Regarding tensorflow, the link you posted is a random old copy of tensorflow, the main branch of tensorflow is not affected. I especially checked the scientific projects before creating the issue and none of the numpy and friends are affected. JPype1 fix a is a simple one line change.
As for blender, they seem to be using private APIs for things for which public APIs exists. Regardless the change is a one liner.
Also if you consider the affected projects to a lot then also consider that the performance improvements will be observed by virtually every python program and application which uses try except and there are a lot of those too
Agreed that this doesnât look very serious. I wonder, would it be better to set it to zero to indicate ânot yet computedâ or is -1 better? Most of the time if people donât fix their code they will just report a bad line number which isnât terrible. Is there a difference between 0 and -1?
Note that âno documentationâ is not a very good argument, and PyTracebackObject looks like a good example for that.
According to git log, the Python API for tracebacks was first documented around 1992. The Python APIâs tb_lineno attribute seems to have been fully documented since then.
In C, thereâs a struct _traceback with a int tb_lineno member. What could it mean? I was 6 in 1992, but I imagine things were pretty clear to anyone working with tracebacks from C.
And youâll need to put the Py_DEPRECATED in #ifdef Py_BUILD_CORE. (I donât think we have a macro for that, yet.)
Deprecating the whole struct â and adding setters/getters/initializer â is also an option.
True. But it does help stability a lot.
FWIW, the API for creating objects could be made more stable â by adding new function each time an argument is added, or by creating with good defaults for the new members and requiring setters. Itâd be a hassle for code objects since they change too often, but I wouldnât be afraid of it here.
I am strong -1 on adding any initializer or setters for PyTracebackObject. If you need to create a traceback, call the type with args just like the Python level TracebackType. There is no need for an initializer C API for every structure at C level unless necessary.
Just by adding function each time code object changes wonât make it a stable API. It will cause more issue than it solves both on the user side and on our side. We have code.replace which can be used. I am -1 on adding any function to set any code object fields or a C level initializer. Just call the Python level type with the C API.
PyTracebackObject *tb_create(
PyTracebackObject *last_traceback,
PyObject *globals, // locals is set to NULL
const char* filename,
const char* funcname,
int linenum);
I think all Cython needs from the PyTracebackObject is a way to get the frame. Although in principle it could probably do that via Python attribute lookup if it came to it.
Wow, the JPype function does a lot: it creates a dummy code object from file/func/line, then it creates a new thread state, linking it to the frame from last_traceback (if any), then it creates a new frame from that thread state, also passing it the dummy code object and the dict of globals, and finally it creates a traceback object linked to the frame and to _last_traceback.
I can totally see that this doesnât work in 3.11 (the big comment in the function shows that the specifics were just reverse-engineered from the code and what works in 3.10). It also looks a bit like what _PyTraceback_Add does (but not quite). That function appears entirely undocumented; it was added for expat by @markshannon.
Maybe Mark has an idea of what we can offer JPype?
Cython and template engines like Jinja like to generate frames/traceback including their own filenames and line numbers. Having a simple C API for that would be nice.
So the API you propose is suboptimalâideally we just give file, line and previous tb, and we modify things so a tb can hold those without dummy frame and code object.
I didnât propose tb_create() API in Python. I just showed whatâs needed in existing projects. If we add a new API, it should simplify tb_create() implementation.