Skip to content

Remove support for __cached__ and __package__ if missing corresponding __spec__ attributes #134088

Open
@picnixz

Description

@picnixz

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

Activity

mkaraev

mkaraev commented on May 16, 2025

@mkaraev
picnixz

picnixz commented on May 16, 2025

@picnixz
Author
xuantengh

xuantengh commented on May 20, 2025

@xuantengh
Contributor

Hi I'd like to work on this. Does it mean for modules without __spec__, we do not set __cached__ nor __package__ for them?

picnixz

picnixz commented on May 20, 2025

@picnixz
MemberAuthor

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.

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
brettcannon

brettcannon commented on May 22, 2025

@brettcannon
Member

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 😅).

serhiy-storchaka

serhiy-storchaka commented on May 31, 2025

@serhiy-storchaka
Member

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.

picnixz

picnixz commented on May 31, 2025

@picnixz
MemberAuthor

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?

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

    interpreter-core(Objects, Python, Grammar, and Parser dirs)stdlibPython modules in the Lib dirtopic-importlibtype-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Remove support for `__cached__` and `__package__` if missing corresponding `__spec__` attributes · Issue #134088 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant