Skip to content

Commit 96c7daa

Browse files
committed
Update pybind11.h
1 parent a8bbfd3 commit 96c7daa

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

include/pybind11/pybind11.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,14 +1342,21 @@ class module_ : public object {
13421342
// GraalPy doesn't support PyModule_GetFilenameObject,
13431343
// so getting by attribute (see PR #5584)
13441344
handle this_module = m_ptr;
1345-
result.attr("__file__") = this_module.attr("__file__");
1345+
if (hasattr(this_module, "__file__")) {
1346+
result.attr("__file__") = this_module.attr("__file__");
1347+
}
13461348
#else
13471349
handle this_file = PyModule_GetFilenameObject(m_ptr);
1348-
if (!this_file) {
1350+
if (this_file) {
1351+
result.attr("__file__") = this_file;
1352+
}
1353+
else if (PyErr_ExceptionMatches(PyExc_SystemError) != 0) {
1354+
PyErr_Clear();
1355+
}
1356+
else {
13491357
throw error_already_set();
13501358
}
1351-
result.attr("__file__") = this_file;
1352-
#endif
1359+
#end
13531360
attr(name) = result;
13541361
return result;
13551362
}

0 commit comments

Comments
 (0)