Importing modules with arguments

Charles Smith charles at sollum.tech
Fri Jul 30 14:54:27 EDT 2021


First off, thanks for the answer. I don't see the cached module as a problem here. If you provide arguments to a module, the goal is "most likely" to alter/parameterize the behavior of the first import. Now, I agree that behavior becomes unpredictable because passing different parameters on subsequent imports won't change the behavior of the imported module . One thing that could be done is to memoize those imports based on the parameters (this is a huge change to how imports works so its a bit yikes). Another solution would be to simply not cache parameterized imports. You sacrifice performance for added flexibility which I think is fair. I do however agree about partial imports. It would be rather complex to properly pass the context but its certainly doable.


More information about the Python-list mailing list