-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
C API: Add a replacement for PySys_GetObject #108512
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
Comments
I propose the name The existing name By the way, the special Py_TRACE_REFS debug build has a |
The name is only the part of the question. Other questions are:
Currently
Case 2 looks like a bug. We should raise explicit exceptions in these cases. But what exceptions? |
IMO this is similar to the new
Well, from the |
I was a rhetorical question. I was just argument in favor of my proposed PySys_GetAttr() name :-) |
@serhiy-storchaka: I'm interested to work on such API, but if you prefer to write it, just tell me. For many years, PySys_GetObject() annoyed me, but I was not motivated enough to change it. For example, I dislike the fact that it returns a borrowed reference. I also dislikes the fact that it returns NULL if there is no attribute and if an error occurs. Also, it never raises any exception, it's bad in many ways :-( |
I have not started to write a code yet. There is a similar function I think that convenient functions for getting an attribute of |
I started to work on preliminary patch and found that |
We should add PySys_GetAttr() with PyObject name and PySys_GetAttrString() with char* name. It would be consistent with other APIs, no? |
There are at least 53 sites in CPython code that can use new functions (currently they use More detailed, per function: 11 All 4 variants are used in almost equal proportions. 4 new functions to replace |
Add functions PySys_GetAttr(), PySys_GetAttrString(), PySys_GetOptionalAttr() and PySys_GetOptionalAttrString().
Oh, I forgot about this old issue! I just created #129367 to propose adding |
IMO PySys_GetOptionalAttrString functions are too much (adding 2 functions is already "a lot") and not worth it. If you want to support optional attribute, you should expect |
I read the PR #111035 which replaces |
Add functions PySys_GetAttr() and PySys_GetAttrString().
… free-threaded build The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed reference, has been replaced by using one of the following functions, which return a strong reference and distinguish a missing attribute from an error: _PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(), _PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
… free-threaded build The use of PySys_GetObject() and _PySys_GetAttr(), which return a borrowed reference, has been replaced by using one of the following functions, which return a strong reference and distinguish a missing attribute from an error: _PySys_GetOptionalAttr(), _PySys_GetOptionalAttrString(), _PySys_GetRequiredAttr(), and _PySys_GetRequiredAttrString().
Feature or enhancement
Proposal:
The
PySys_GetObject()
function has two flaws:We need to add a replacement free from these flaws. Any ideas about the API and the name?
Links to previous discussion of this feature:
Linked PRs
The text was updated successfully, but these errors were encountered: