Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 additions & 0 deletions include/pybind11/pybind11.h
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,11 @@ class module_ : public object {
if (doc && options::show_user_defined_docstrings()) {
result.attr("__doc__") = pybind11::str(doc);
}
handle this_file = PyModule_GetFilenameObject(m_ptr);
if (!this_file) {
throw error_already_set();
}
result.attr("__file__") = this_file;
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