Repository navigation
Replace Loader with PEP 451 _Loader protocol in _importlib_modulespec.pyi annotations. - #2626
Conversation
For built-in imports, ModuleSpec.loader is an uninstantiated BuiltinImporter class, not an instance.
|
Same for frozen imports and |
|
I am not sure I like this change. The importlib documentation states that loaders are defined as objects having a |
|
Hi, thanks for the feedback @srittau. I'm a bit confused with your suggestion - it looks to me like the only |
|
Sorry, I was a bit confused from the circular import prevention going on in the stubs. But yes I was suggesting to add a |
This protocol implements the "loader" interface defined in PEP 451.
|
I think that's a great solution; I actually wasn't familiar with Here's a patch. |
….pyi annotations. (python#2626)
Currently, we have these errors: $ mypy ./tools/testing/kunit/*.py tools/testing/kunit/kunit_kernel.py:213: error: Item "_Loader" of "Optional[_Loader]" has no attribute "exec_module" tools/testing/kunit/kunit_kernel.py:213: error: Item "None" of "Optional[_Loader]" has no attribute "exec_module" tools/testing/kunit/kunit_kernel.py:214: error: Module has no attribute "QEMU_ARCH" tools/testing/kunit/kunit_kernel.py:215: error: Module has no attribute "QEMU_ARCH" exec_module =========== pytype currently reports no errors, but that's because there's a comment disabling it on 213. This is due to python/typeshed#2626. The fix is to assert the loaded module implements the ABC (abstract base class) we want which has exec_module support. QEMU_ARCH ========= pytype is fine with this, but mypy is not: python/mypy#5059 Add a check that the loaded module does indeed have QEMU_ARCH. Note: this is not enough to appease mypy, so we also add a comment to squash the warning. Signed-off-by: Daniel Latypov <[email protected]>
For built-in imports,
ModuleSpec.loaderis an uninstantiatedBuiltinImporterclass.