Skip to content

Commit ff4ba4b

Browse files
committed
[mypyc] Getting capsule pointer from module instead of PyCapsule_Import.
1 parent 52888ae commit ff4ba4b

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

mypyc/lib-rt/module_shim.tmpl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ PyInit_{modname}(void)
55
{{
66
PyObject *tmp;
77
if (!(tmp = PyImport_ImportModule("{libname}"))) return NULL;
8+
PyObject *capsule = PyObject_GetAttrString(tmp, "init_{full_modname}");
89
Py_DECREF(tmp);
9-
void *init_func = PyCapsule_Import("{libname}.init_{full_modname}", 0);
10+
void *init_func = PyCapsule_GetPointer(capsule, "{libname}.init_{full_modname}");
11+
Py_DECREF(capsule);
1012
if (!init_func) {{
1113
return NULL;
1214
}}

mypyc/test-data/commandline.test

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,3 +243,22 @@ def i(arg: Foo) -> None:
243243

244244
[file test.py]
245245
names = (str(v) for v in [1, 2, 3]) # W: Treating generator comprehension as list
246+
247+
[case testSubPackage]
248+
# cmd: pkg/sub/foo.py
249+
from pkg.sub import foo
250+
251+
[file pkg/__init__.py]
252+
253+
[file pkg/sub/__init__.py]
254+
print("importing...")
255+
from . import foo
256+
print("done")
257+
258+
[file pkg/sub/foo.py]
259+
print("imported foo")
260+
261+
[out]
262+
importing...
263+
imported foo
264+
done

0 commit comments

Comments
 (0)