Repository navigation
Remove support for __cached__ and __package__ if missing corresponding __spec__ attributes #134088
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancementinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
on May 16, 2025 picnixz commented
on May 16, 2025 on May 16, 2025 · Hidden as resolvedAuthorshow commentMore actionsHi I'd like to work on this. Does it mean for modules without
__spec__, we do not set__cached__nor__package__for them?No my bad, the title is misleading :') it's only if setting the attribute on
__spec__failed that we would not allow setting it otherwise. The exact description is in pending-removal-in-315 but I would like the feedback from an importlib expert.Reacted by Xuanteng Huang- changed the title
[-]Remove support for `__cached__` and `__package__` on specless modules[/-][+]Remove support for `__cached__` and `__package__` if missing corresponding `__spec__` attributes[/+]on May 20, 2025 FYI
__package__and__cached__are slated for removal in 3.15 (although being slated for removal doesn't mean Barry and I will get to it at the core dev sprints which is our traditional time to try and remove those attributes 😅).It cannot be done now, because the deprecation was not complete. The warnings were emitted not in all cases. See #122255.
We first need to start emitting deprecation warnings in all cases, this will restart the deprecation period.
Oh. So let's first remove the different mentions to this removal (I haven't worked at all on this one because I didn't know what to do and how to do it as well) maybe?
It cannot be done now, because the deprecation was not complete.
But that was for
__loader__and this issue is about__cached__and__package__.FYI #142165 drops setting
__cached__, period.
Feature or enhancement
Setting
__cached__or__package__on a module while failing to set the corresponding__spec__attributes is deprecated since Python 3.12 (see #97879).cc @brettcannon