-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs of deprecated C function should propose replacement in C, not in Python #129342
Comments
Like |
kind of works, but it returns the full path, not just the executable name. |
Don't use
I suggested |
Thanks. These replacements for
Replacement of |
https://docs.python.org/3/c-api/init.html#c.Py_GetPythonHome says: "Get PyConfig.home or PYTHONHOME environment variable instead." Retrieving a Python enviroment variable from C seems feasible but lengthy. So I tried PyConfig.home:
Seems to work. Is there a simpler solution? |
@serhiy-storchaka I just see on PEP731 that you are member of the C API working group. So you are the right person to ask: WHY these deprecations? They break production code, and now it turns out that there is not even a 1:1 replacement... |
I added
|
Of course a 1:1 replacement is much better than a multi-line workaround. Is there a similarly simple solution for Py_GetProgramFullPath and Py_GetPath? Nonethess, my question goes: WHY these deprecations? Have you really well pondered aginst the damage done (not least to Python's reputation) by breaking things? |
Would you mind to elaborate on your use case? You call
In Python 3.8, I designed and implemented PEP 587 "Python Initialization Configuration" which unifies the "Python initialization". Slowly (since Python 3.8), I deprecated the old way to configure Python. How can I help you to migrate your code towards newer APIs which are not deprecated? Does |
Sorry, it was discussed before I became the member of the C API working group, so I am not aware of arguments. I guess this is related to handling global state at different stages of Python initialization and shutdown, and maybe to supporting multiple interpreters. But we should be more conservative with deprecating the public C API. For every deprecated function we should document an alternative that works in all maintained Python versions. If |
My use case: in a complex software with C++ core and Python API [1,2], we want to introspect the state of an embedded Python interpreter for various debugging purposes. Anyway, functions I had hoped that the Python community had learned from the forced upgrade from Py2 to Py3. But no, you are breaking things within major 3, with relatively short transition periods. This is in stark contrast with the emphasis C++ is putting on backwards compatibility, and it raises serious doubts whether C++ and Python is a good combination in a software project that is meant to be maintained for decades to come. This said, a well-documented 1:1 drop-in replacement like But why not leave [1] https://www.bornagainproject.org/ |
I just ran a code search on PyPI top 8,000 projects using regex
I recently postponed these deprecations from Python 3.14 to Python 3.15 since PEP 741 landed in Python 3.14. If the delay is too short, we can postpone the deprecation even later. |
Regarding my own needs, the above workaround just works. Thank you for your kind offer, but no need to postpone deprecation just for me. If I keep insisting here, then it's not for my own immediate needs but for the sake of the user community at large. I am not convinced by your statistics. Top 8k is not enough if there are 600k projects. And more importantly, C projects with embedded Python interpreter don't typically go to PyPI. I just did a quick GitHub code search. 100s of hits for |
I wrote documentation PR gh-129361 to explain how to replace Py_GetProgramName() in C, rather than in Python. Example:
It's just to get a coarse idea on the ratio of impacted projects. The answer on top 8k is: "more than zero" :-) but the ratio is low. PEP 741 lists a few projects embedding Python. But usually these projects only "set" the configuration, they don't need to "get" the configuration. |
The problem of this API is that the returned string lifetime is undefined: the caller doesn't have to call Moreover, since we have to store a copy of this string (to respect the API lifetime), the string can become inconsistent if the related The implementation is non-trivial because it has to use a specific memory allocator ( I did my best to maintain backward compatibility when I implemented PEP 587 (PyConfig). But the backward compatibility has a cost in term of maintenance burden. Deprecating (and removing) a few functions should reduce this cost. I'm sorry that you're application is impacted and that the documentation on how to update wasn't great. I'm aware of these problems and that's why I designed PEP 741 which might enter the stable ABI in the future. The stable ABI prevents these annoyance since the ABI is guaranteed to stay unchanged. In Python 3.14, it's not in the stable ABI yet. |
Thank you, Victor, for these explanations and for the perspective that things will become more stable in the future. |
One more question please: is my replacement code correct, or do I need to add some
|
You should not call |
Don't call Normally, you should check every C API call for errors. |
How? Where are the docs? https://docs.python.org/3/c-api/index.html offers no way to read the manual in one page so that one could do a full-text search. It has a search widget near the bottom though. However, search for |
How to do without? Calling |
It should work if |
works for "executable" but not for "path". For the latter, |
Yes, because If you only want to format a string containing some Python settings, it may be easier to write that code in Python and then execute it with |
Note, Python does not use SemVer or any similar versioning scheme (it predates them), we have a policy on deprecations and removals, which describes our commitments to backwards (in)compatibility. |
@AA-Turner PEP 387 is excellent reading indeed. It says "the incompatibility should be easy to resolve in affected code". Where "easy" probably means less than: spending a whole working day without arriving at a valid replacement in spite of substantial help from two volunteeers here. |
Fixed by change 632ca56. Thanks for the bug report. |
Documentation
In the 3.13 Python/C API Reference Manual, page "Initialization, Finalization, and Threads",
Py_GetProgramName()
and several other C functions are declared deprecated. To replace them, it is suggested "Get sys.executable instead".As maintainer of a C program, I find this not helpful. I would need a drop-in replacement in C, not a reference to a Python variable.
Linked PRs
The text was updated successfully, but these errors were encountered: