GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||
GeezerVison is showing github.com — gh-106915: Add PyImport_ImportOrAddModule() function by vstinner · Pull Request #111559 · python/cpython Conversation
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Remove PyImport_AddModuleRef() function.
b6f8588 to
2f3cc67
Compare
|
@encukou proposes |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Oh, if PyImport_AddModuleRef() is removed, I should update pythoncapi-compat as well: https://pythoncapi-compat.readthedocs.io/en/latest/api.html#c.PyImport_AddModuleRef |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
API-wise, this looks good to me, thank you! We should of course wait if the C-API WG is approved.
In the docs, I'd mention creating a new (empty) module more prominently, to make extra sure people don't assume the module is imported if missing.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I applied your suggestions manually to also update the doc in Include/import.h at the same time. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The working group doesn't exist yet. Maybe @gvanrossum @zooba and @iritkatriel want to review this PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@encukou: Would you mind to review the updated PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'll get to it next week. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
(Got to it sooner!)
+1 from me on the functionality. Thank you!
It looks OK API-wise, too. I recommend checking with the other CAPI-workgroup-to-be members if it fits the direction they want.
One thing to note is the allocation of the “lesser” and “greater” result (0 or 1) for this kind of “setdefault”-style API: should 1 mean “created/assigned” like here, or “found” like in “getitem”-style API?
As far as I'm concerned, it could go either way, but some people might have a strong opinion. And this could become a precedent.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Aha. The function is called import or add: add comes second, so I suppose that it should return success (1) if import is successful. Also, I think that returning 1 if the module exists in sys.modules which be consistent with PyDict_GetItemRef() API. I modified the PR to return 1 if the module is found in sys.modules, or 0 if the module was created (and then added to sys.modules). |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
@encukou: Would you mind to review the updated PR? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I like this better, thanks! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think we've still got to thoroughly discuss the return value convention, and personally in this case I'd prefer to see Right now it isn't immediately obvious whether the existing value of the module argument is what is going to be added, or whether a new one will be created ( If there's a need to hurry this API in, then I won't block it, but I would ask that it not be used as precedent when we come to deciding the guideline. If we decide to go the other way, it can just be an exception/wart, but we shouldn't rush an API and then use that to determine the guideline. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Well, I added @encukou: So, which API do you prefer?
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Please add your proposal/ideas there. New API is being added without waiting for that discussion...
As always with new API, I'd prefer waiting until the WG can discuss it.
What I prefer now, in the middle of the discussions?
For 3., the
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
This PR implements what @encukou proposed there: #106915 (comment) But apparently, @encukou now dislikes the API. I don't have the bandwidth to dig into the issue. @encukou: if you're motivated, please go ahead. For now, I prefer to close this PR. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.