Thank you, I was more or less aware of this simple solution, but the problem is that it is vulnerable to certain relatively innocent code changing the meaning of code later on (e.g. if the “lots of code” includes a file that imports Base.isopen), so I wanted to do something that would help protect against such errors. I did actually work some more with @mikmoore s suggestion of using using rather than import and made a little package implementing this (and found another bug in my original post), but in the end, I was not very satisfied with this path and ended up just putting an assertion in the last line of the module and a comment explaining it:
module MyModule
# Lots of code
include("file_that_defines_isopen.jl")
# Explanation for the next line
@assert parentmodule(isopen) != Base
end
Another alternative could just have been to include this test in the testsuite for the package.