-
Notifications
You must be signed in to change notification settings - Fork 672
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Replace deprecated imp module with importlib #1846
Comments
I agree. This is something we'll need to address before we can support Python 3.12. Our only usage of
I'm actually not seeing any suggestions for @hugovk - any ideas what we should be using? |
See pyinvoke/invoke#215 for a PR that replaced it with That code was just updated now looks like this: from importlib.util import spec_from_loader
from types import ModuleType
try:
from importlib.machinery import SourceFileLoader
except ImportError: # PyPy3
from importlib._bootstrap import ( # type: ignore[no-redef]
_SourceFileLoader as SourceFileLoader,
)
def load_source(name: str, path: str) -> Dict[str, Any]:
if not os.path.exists(path):
return {}
loader = SourceFileLoader("mod", path)
mod = ModuleType("mod")
mod.__spec__ = spec_from_loader("mod", loader)
loader.exec_module(mod)
return vars(mod) Does that help? |
@hugovk - yes, this is very helpful. Thank you. |
Fixed by PR 2170 |
🌱 Describe your Feature Request
This library uses the
imp
module which has been deprecated since Python 3.4 and set for removal in 3.12:PendingDeprecationWarning
since 3.4 (2014)DeprecationWarning
since 3.5 (2015)DeprecationWarning
to say removal in 3.12 since 3.10 (2021)Python 3.12 is set for release on 2023-10-02 and this library is one of the top 5,000 most-downloaded from PyPI.
Please could you upgrade to use
importlib
? Theimp
docs have suggestions on what to use to replace each function and constant.The text was updated successfully, but these errors were encountered: