KEMBAR78
[mypyc] Getting capsule pointer from module instead of PyCapsule_Import. by advait-dixit · Pull Request #18286 · python/mypy · GitHub
Skip to content

Conversation

advait-dixit
Copy link
Contributor

@advait-dixit advait-dixit commented Dec 12, 2024

Fixes mypyc/mypyc#999.

PyCapsule_Import was failing in sub-packages. Since the capsule is an attribute of the module, we can access the capsule from the module instead of importing it.

@advait-dixit
Copy link
Contributor Author

@hauntsaninja , @JukkaL : Can you please take a look at this pull request? I think it fixes an import bug that has been reported by many users.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the issue! Looks good overall, just one error check seems to be missing.

{{
PyObject *tmp;
if (!(tmp = PyImport_ImportModule("{libname}"))) return NULL;
PyObject *capsule = PyObject_GetAttrString(tmp, "init_{full_modname}");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check for null return. Otherwise we may decref a null pointer below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed it. Thanks.

@JukkaL JukkaL merged commit f445369 into python:master Dec 19, 2024
13 checks passed
@advait-dixit advait-dixit deleted the fix_circ_imp branch December 19, 2024 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

mayhem with nested packages and relative import

2 participants