Visitar URL original
Remove support for `__cached__` and `__package__` if missing corresponding `__spec__` attributes · Issue #134088 · python/cpython · GitHub
Skip to content

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

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

  1. added
    type-featureA feature request or enhancement
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    stdlibStandard Library Python modules in the Lib/ directory
    on May 16, 2025
  2. mkaraev commented on May 16, 2025

    @mkaraev
  3. picnixz commented on May 16, 2025

    @picnixz
    Author
  4. 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?

  5. 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.

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

  8. 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.

  9. 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?

  10. brettcannon commented on Aug 8, 2025

    @brettcannon
    Member

    It cannot be done now, because the deprecation was not complete.

    But that was for __loader__ and this issue is about __cached__ and __package__.

  11. brettcannon commented on Dec 1, 2025

    @brettcannon
    Member

    FYI #142165 drops setting __cached__, period.

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)stdlibStandard Library Python modules in the Lib/ directorytopic-importlibtype-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions