-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
sys.set_lazy_imports_filter loses information when doing relative imports #148026
Copy link
Copy link
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Problem takes multiple files to demo, so I've put it in a gist https://gist.github.com/msullivan/90996c05e8c8e01c2492d1c657b59d52. If you put all those files in test and run python3 -m test.lazy_lol, I get:
importer='__main__' name='' fromlist=('go',)
importer='test.go' name='uhoh' fromlist=('x',)
The problem is that the filter gets a relative path, but nothing indicates that, so there is no way to distinguish between from uhoh import x and from .uhoh import x.
The PEP doesn't really touch on what the right thing is here.
Potential fixes:
- Put a leading
.in thename, so.uhohin that case - Turn it into a fully resolved path, so
test.uhoh. (Assuming we have the info to do it at that point? I haven't looked carefully yet)
One other snag is that if option 1 is chosen, we still wouldn't be able to resolve the location when the importer is __main__ (unless we could also change that).
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-lazy-importstype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error