Skip to content

Reflect it that sys.lazy_modules is no longer a flat set #145057

@johnslavik

Description

@johnslavik

Bug report

Bug description:

sys.lazy_modules is now a dict[str, set[str]], not a flat set. There's some places in the stdlib code that incorrectly suggests the older invariant.

Most notable example:

def test_lazy_modules_attribute_is_set(self):
"""sys.lazy_modules should be a set per PEP 810."""
self.assertIsInstance(sys.lazy_modules, dict)

The PEP needs updating as well -- https://peps.python.org/pep-0810/#lazy-import-mechanism -- @DinoV, I think this is something you were working on, or is it open for contrib?

I'm happy to pick this one up (i.e. fixing our code to reflect sys.lazy_modules is a dict) if you'd like that! (Please reassign otherwise.)

cc @pablogsal @DinoV @brittanyrey @Yhg1s

CPython versions tested on:

CPython main branch

Operating systems tested on:

No response

Metadata

Metadata

Assignees

Labels

3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions