The error appears only when I try to use the script function
encapsulated in a module file, calling it the function from another
python file.
That doesn't make any sense - Python and Modeller don't care about where
the function is. At any rate, to reproduce your problem I need to see
all your files, not just one of them.