-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Description
When loading a module dynamically with the following code:
from importlib.util import spec_from_file_location, module_from_spec
from pathlib import Path
file = Path.cwd() / etc...
spec = spec_from_file_location(str(file), str(file))
spec.loader.exec_module(module_from_spec(spec))
Mypy fails with the following errors:
test_loader.py:7: error: Item "_Loader" of "Optional[_Loader]" has no attribute "exec_module"
test_loader.py:7: error: Item "None" of "Optional[_Loader]" has no attribute "exec_module"
For the first error, from what I understand, the problem is that _Loader
does not have exec_module while Loader
does, and ModuleSpec.loader
is set to Optional[_Loader]
.
Removing the underscore here
loader = ... # type: Optional[_Loader] |
The second error is due to
Optional
... it appears that None
is a valid loader value (when the loader is not found).Metadata
Metadata
Assignees
Labels
No labels