Skip to content

Commit 7239612

Browse files
committed
set the __package__ attribute for extension modules
1 parent 7cc3ecd commit 7239612

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

graalpython/lib-graalpython/python_cext.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,15 @@ def _PyModule_CreateInitialized_PyModule_New(name):
103103
if _imp._py_package_context.endswith(name):
104104
name = _imp._py_package_context
105105
_imp._py_package_context = None
106-
return moduletype(name)
106+
new_module = moduletype(name)
107+
# TODO: (tfel) I don't think this is the right place to set it, but somehow
108+
# at least in the import of sklearn.neighbors.dist_metrics through
109+
# sklearn.neighbors.ball_tree the __package__ attribute seems to be already
110+
# set in CPython. To not produce a warning, I'm setting it here, although I
111+
# could not find what CPython really does
112+
if "." in name:
113+
new_module.__package__ = name.rpartition('.')[0]
114+
return new_module
107115

108116

109117
def PyModule_SetDocString(module, string):

0 commit comments

Comments
 (0)