-
Notifications
You must be signed in to change notification settings - Fork 3
FIX: Import importlib functions directly
#68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Interesting.. maybe |
|
Or actually now that I am thinking about it more... We can just do import importlib.util
....
if importlib.util.find_specSo basically my updated understanding is that at least in python 3.10.11+, the supported API of EDIT: I just saw your comment @mscheltienne , yes I think you are right! |
|
Yes, reading through the rest of that post, |
This reverts commit 6a1f2fb.
|
@mscheltienne WDYT? Is it weird to import |
|
I would replace it with 2 (very) explicit imports: (might have made a typo, I'm on my phone) |
find_spec for importmodule inside a try/except blockimportlib functions directly
|
Thanks @scott-huberty |
Hey @mscheltienne ,
I copied the
import_optional_dependencycode into an environment where I don't have thetemplate-pythondeps installed, and ran into what I think is a bug inimportlib. TL;DR in python 3.10.11+ I don't think you normally can doimportlib.util.find_spec(see this comment from a Cpython developer).I am not 100% sure about exactly what is going on, but here is what I've found out so far:
mamba create -n "importlib_test" python=3.10.13But I can work around this with:
So my current best guess is that one of the
template-pythondependencies does something likefrom importlib.util import ...which exposes theimportlib.utilmodule, allowingtemplate-pythonto call it without issue?Anyways, if your tests are passing on python 3.10.11+ then this might not be an actual issue. But if it is, then the PR here swaps out
importlib.util.find_spec(which I actually really liked!) for atry....exceptblock.Up to you on whether you want to incorporate this to
main.