I was wondering if passing module objects to a class or object which requires it rather than using import might not be a bad idea, as it avoids hard dependencies on those modules.
I was wondering if someone more aware of the Python Zen than I might be able to explain why this is a terrible/not terrible idea?
What you’re talking about is called dependency injection and is considered a good practice for making your code testable. I don’t think there’s anything about Python that would make it unPythonic or a bad practice.
There are other ways you could do it in Python, for example by importing different modules depending on some kind of flag you pass in:
But passing a reference to the module you wish to use is more flexible, separates concerns better, and is no less Pythonic than passing a reference to a class or instance (or string or integer) you wish to use.
For the ordinary (non-test) use case, you can use a default argument value: