amogorkon / justuse

Just use() code from anywhere - a functional import alternative with advanced features like inline version checks, autoreload, module globals injection before import and more.
MIT License
49 stars 8 forks source link

Problem with mixing up use-str with use-path (ModuleNotFoundError: __path__ attribute not found #477

Open amogorkon opened 2 years ago

amogorkon commented 2 years ago

tried to use("tagger.py") a file in a parent directory, which should raise some good error but instead it crashed with

ImportError while importing test module 'f:\Dropbox (Privat)\code\JKitten\tests\test_units.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
G:\Python398\lib\importlib\util.py:96: in find_spec
    parent_path = parent.__path__
E   AttributeError: module 'tagger' has no attribute '__path__'

The above exception was the direct cause of the following exception:
G:\Python398\lib\importlib\__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
tests\test_units.py:6: in <module>
    tagging = use("tagger.py")
G:\Python398\lib\site-packages\use\main.py:135: in __call__
    return self.__implementation(*args, **kwargs)
G:\Python398\lib\site-packages\use\tools.py:46: in wrapper
    return dispatcher.dispatch(args[1].__class__)(*args, **kwargs)
G:\Python398\lib\site-packages\use\main.py:669: in _use_str
    return self._use_package(
G:\Python398\lib\site-packages\icontract\_checkers.py:641: in wrapper
    result = func(*args, **kwargs)
G:\Python398\lib\site-packages\use\main.py:725: in _use_package
    spec = importlib.util.find_spec(module_name.replace("-", "_"))
G:\Python398\lib\importlib\util.py:98: in find_spec
    raise ModuleNotFoundError(
E   ModuleNotFoundError: __path__ attribute not found on 'tagger' while trying to find 'tagger.py'