fix AttributeError crash when using --import-mode=importlib#13029
fix AttributeError crash when using --import-mode=importlib#13029nicoddemus merged 2 commits intopytest-dev:mainfrom
AttributeError crash when using --import-mode=importlib#13029Conversation
AttributeError crash when using --import-mode=importlib
nicoddemus
left a comment
There was a problem hiding this comment.
Thanks @dongfangtianyu for investigating it and opening a fix so quickly!
Left some small comments, can you take a look?
Backport to 8.3.x: 💚 backport PR created✅ Backport PR branch: Backported as #13037 🤖 @patchback |
|
This is very dangerous, as it will override an already imported module if it’s not a package (i.e. lacks the For example:
Running A shorter, but more artificial example:
Running |
closes #13026 .
changelogfolder.Only parent modules with the
__path__attribute can be used by thefind_specfunction, and most of the standard library does not meet this condition.https://github.com/python/cpython/blob/3.9/Lib/importlib/_bootstrap_external.py#L1223
So this PR adds a condition check.