On 04/06/2021 19:29, Steve Dower wrote:
...........
While we were investigating the reliably broken behaviour, we figured that related behaviour was
*unreliably* broken on all platforms.
Specifically, if you imported a module through a relative path (resolved to CWD), changed the CWD, cleared the module
cache, and reimported, you would still get the original module, contrary to the intent of getting the newly resolved
module. ("Correct" code would have also cleared the import path caches, not just sys.modules.) This was because the
module info was cached using the relative path, and so would be used later even though its absolute path had changed.
Someone reported this change in 3.8 and we decided to revert it in existing released, because the bugfix was for an
obscure enough situation that it really wasn't worth breaking any existing versions. For unreleased versions, it's
better to fix it so that imports will be more reliable in the future.
Unfortunately we are using these relative imports to implement plugins for an xml language processor so this is likely
not just an accident of ordering the failing tests. I agree we have to get a plugin module a bit more directly using the
import internals. I still think we might need to control sys.path as presumably the plugin code could have imports of
parallel modules.
I'm beginning to understand that messing about with sys.path/modules/meta_path
etc etc is a lot harder than it used to be.
Incidentally I find that I am able to import a namespace module directly; this
code doesn't crash (at least in python >= 3.6
###################################################
#timpA.py don't run with any meaningful directory A
import importlib
def main():
module = importlib.import_module('A')
print('module=%r' % module)
if __name__=='__main__':
main()
###################################################
in python 3.6-3.9 this prints out "module=<module 'A' (namespace)>" in 3.10.0b1
it prints
"module=<module 'A' (<_frozen_importlib_external._NamespaceLoader object at
0x7f1c8a22fe20>)>".
I thought I had to use pkgutils or pkg_resources to mess with these new-fangled
packages.
Likewise I find that the python statement 'import A' also doesn't fail and A is
a namespace. I feel quite stupid now :(
--
Robin Becker
_______________________________________________
Python-Dev mailing list -- python-dev@python.org
To unsubscribe send an email to python-dev-le...@python.org
https://mail.python.org/mailman3/lists/python-dev.python.org/
Message archived at
https://mail.python.org/archives/list/python-dev@python.org/message/KMJAQUGSXINVBLQOMREURUFN4LVCEIVX/
Code of Conduct: http://python.org/psf/codeofconduct/