ManderaGeneral / generalimport

Handle all your optional dependencies with a single call!
https://pypi.org/project/generalimport/
Apache License 2.0
16 stars 1 forks source link

Imports outside scope affected if import within scope triggered first #42

Open Mandera opened 1 year ago

Mandera commented 1 year ago

I think that might be the issue, flask is iterating module names internally with this code

    for module in list(sys.modules.values()):
        name = getattr(module, "__file__", None)

        if name is None or name.startswith(_ignore_always):
            continue

Yielding

    if name is None or name.startswith(_ignore_always):
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "D:\Venvs\Python311\Lib\site-packages\generalimport\fake_module.py", line 19, in error_func
    raise MissingOptionalDependency(f"Optional dependency {name} was used but it isn't installed.")
generalimport.exception.MissingOptionalDependency: Optional dependency 'pandas' was used but it isn't installed.

Didn't look too much into it, but this seems like an issue! Could allow string methods or something, but that's not the root issue

Mandera commented 1 year ago
Mandera commented 1 year ago

Possible solutions: