-
-
Notifications
You must be signed in to change notification settings - Fork 8.2k
py/builtinimport: support relative import in custom __import__ callbacks #6665
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
base: master
Are you sure you want to change the base?
py/builtinimport: support relative import in custom __import__ callbacks #6665
Conversation
The globals need to be forwarded from the callers context.
+1 |
globals() needs to be provided in case __import__ is a Python function
According to documentation time() has a precision of at least 1 second. This test runs for 2.5 seconds and calls all utime functions every 100ms. Then it checks if they returned enough different results. All functions with sub-second precision will return ~25 results. This test passes with 15 results or more. Functions that do not exist are skipped silently.
With MICROPY_FLOAT_IMPL_FLOAT the results of utime.time(), gmtime() and localtime() change only every 129 seconds. As one consequence tests/extmod/vfs_lfs_mtime.py will fail on a unix port with LFS support. With this patch these functions only return floats if MICROPY_FLOAT_IMPL_DOUBLE is used. Otherwise they return integers.
added support for the separators keyword argument in ujson's dump and dumps. added keyword argument indent, only accepts indent=None. indent was only added because it is connected to separators.
…s' into dev" This reverts commit 4a36076.
…ive-import' into dev" This reverts commit 8413c46.
The globals need to be forwarded from the callers context.
globals() needs to be provided in case __import__ is a Python function
Support relative import in custom __import__ callback
…-name fix name for macOS mpy-cross universal build
This is an automated heads-up that we've just merged a Pull Request See #13763 A search suggests this PR might apply the STATIC macro to some C code. If it Although this is an automated message, feel free to @-reply to me directly if |
The globals need to be forwarded from the callers context.
This pull request adds a test with relative import and override as well as a fix.
I've tried to use a custom python function for import to make some performance measurements (actually tracking approximate memory usage). There i noticed that's impossible for a python handler function to support relative imports (
level
> 0). This is due to the globals thatmp_builtin___import__
is getting are from the custom callback instead of the module whereimport
/__import__
was called. So the lookup of__path__
gives the wrong value.The solution is that
mp_import_name
inruntime.c
gets the globals and passes them along in de parameter that already exists for this purpose (i see CPython is doing this too).mp_builtin___import__
uses theglobals
parameter or falls back to the old behavior ifNone
is passed or fewer positional args are provided.