Skip to content

sys.set_lazy_imports_filter loses information when doing relative imports #148026

Closed as duplicate

Description

@msullivan

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:

  1. Put a leading . in the name, so .uhoh in that case
  2. 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

Activity

  1. brittanyrey commented on Apr 3, 2026

    @brittanyrey
    Contributor

    I think we probably want to pass back the absolute path to the user here. (option 2)

  2. picnixz commented on Apr 4, 2026

    @picnixz
    Member

    So, Pablo opened a duplicate issue but since he is one of the PEP authors and already has a fix for it I am going to close this one

  3. pablogsal commented on Apr 4, 2026

    @pablogsal
    Member

    whops! Sorry @msullivan i totally missed this issue :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions