Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,19 @@ class module_ : public object {
if (doc && options::show_user_defined_docstrings()) {
result.attr("__doc__") = pybind11::str(doc);
}

#ifdef GRAALVM_PYTHON
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Suggested change
#ifdef GRAALVM_PYTHON
#if defined(GRAALVM_PYTHON) && GRAALPY_VERSION_NUM < 0x190000

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggestion applied with commit 4682e14

// GraalPy doesn't support PyModule_GetFilenameObject,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This is fine if you want to keep it, but the official PyModule_GetFilenameObject() seems most future proof, compared to referencing "__file__" directly.

We have 7 defined(GRAALVM_PYTHON) already under include/pybind11/, I'd lean towards adding another one here.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Okay, done.

// so getting by attribute
handle this_module = m_ptr;
result.attr("__file__") = this_module.attr("__file__");
#else
handle this_file = PyModule_GetFilenameObject(m_ptr);
if (!this_file) {
throw error_already_set();
}
result.attr("__file__") = this_file;
#endif
attr(name) = result;
return result;
}
Expand Down
1 change: 1 addition & 0 deletions tests/test_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_nested_modules():
)
assert m.__name__ == "pybind11_tests.modules"
assert ms.__name__ == "pybind11_tests.modules.subsubmodule"
assert m.__file__ == ms.__file__

assert ms.submodule_func() == "submodule_func()"

Expand Down