GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — `importlib.abc.SourceLoader` issues `DeprecationWarning` because it inherits from `ResourceLoader` · Issue #137426 · python/cpython

importlib.abc.SourceLoader issues DeprecationWarning because it inherits from ResourceLoader #137426

New issue
Copy link
New issue
Copy link
Closed
Closed
importlib.abc.SourceLoader issues DeprecationWarning because it inherits from ResourceLoader#137426
Copy link
Assignees
brettcannon
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@TTsangSC
TTsangSC
opened on Aug 5, 2025
Issue body actions

Bug report

Bug description:

Problem

  • importlib.abc.SourceLoader itself does not seem to be deprecated as far as the docs go, either in 3.14 or 3.15.
  • However, since it inherits from the deprecated importlib.abc.ResourceLoader, a DeprecationWarning is issued at instantiation time since 3.14.

Example

import os
import sys
import warnings
from collections.abc import Iterable
from importlib.abc import SourceLoader
from importlib.machinery import ModuleSpec
from typing import Protocol


class FinderLike(Protocol):
    def find_spec(self, fullname: str) -> ModuleSpec | None: ...


class MyLoader(SourceLoader):
    """Bare-bone `SourceLoader` subclass, only providing implementations for the abstract methods."""
    @staticmethod
    def get_data(path: os.PathLike | str) -> bytes:
        with open(path, mode='rb') as fobj:
            return fobj.read()

    @staticmethod
    def get_filename(fullname: str, finders: Iterable[FinderLike] | None = None) -> str:
        if finders is None:
            finders = (
                f for f in sys.meta_path
                if callable(getattr(f, 'find_spec', None))
                if not isinstance(f, MyLoader)  # Avoid circular dependence
            )
        for finder in finders:
            try:
                spec = finder.find_spec(fullname)
                if spec is None: raise TypeError
            except (TypeError, ImportError):
                continue
            if spec.origin is not None and os.path.isfile(spec.origin):
                return str(spec.origin)
        raise ImportError(f'cannot find filename for `{fullname}`')


with warnings.catch_warnings():
    warnings.filterwarnings('error', category=DeprecationWarning)
    loader = MyLoader()  # DeprecationWarning: importlib.abc.ResourceLoader is deprecated in favour of supporting resource loading through importlib.resources.abc.TraversableResources.

Questions

  • Is this to be considered a bug? Or is SourceLoader supposed to be deprecated too?
  • If the former, how can it be fixed? If the latter, should the docs be updated?

Possibly related issues

#89710, #121604

CPython versions tested on:

3.14

Operating systems tested on:

macOS

Linked PRs

  • GH-137426: Remove code deprecation of importlib.abc.ResourceLoader #137567
  • [3.14] GH-137426: Remove code deprecation of importlib.abc.ResourceLoader (GH-137567) #137654

Activity

  1. TTsangSC
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    on Aug 5, 2025
  2. StanFromIreland
    added
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-importlib
    on Aug 5, 2025
  3. brettcannon
    added
    3.14bugs and security fixesbugs and security fixes
    3.15bugs and security fixesbugs and security fixes
    release-blocker
    on Aug 8, 2025
  4. ezio-melotti
    added this to Release and Deferred blockers 🚫on Aug 8, 2025
  5. github-project-automation
    moved this to Todo in Release and Deferred blockers 🚫on Aug 8, 2025
  6. brettcannon commented on Aug 8, 2025

    @brettcannon
    brettcannon
    on Aug 8, 2025
    Member
    More actions
    • Is this to be considered a bug? Or is SourceLoader supposed to be deprecated too?

    It's a bug in so much as SourceLoader isn't deprecated.

    • If the former, how can it be fixed?

    One option is for SourceLoader to stop inheriting from ResourceLoader and copy over the abstract method from it (as well as update the docstring and documentation).

    What I'm wondering about, though, is why didn't the tests catch this?

  7. brettcannon commented on Aug 8, 2025

    @brettcannon
    brettcannon
    on Aug 8, 2025
    Member
    More actions

    @hugovk not sure if this should be a release blocker, made it one just in case since the fix might be annoying in a point release if we change the inheritance structure.

  8. brettcannon commented on Aug 8, 2025

    @brettcannon
    brettcannon
    on Aug 8, 2025
    Member
    More actions

    I found my mistake: I merged 27494dd probably thinking the warning suppression was for tests of ResourceLoader instead of SourceLoader.

  9. brettcannon commented on Aug 8, 2025

    @brettcannon
    brettcannon
    on Aug 8, 2025
    Member
    More actions

    Another option is to drop the warning on ResourceLoader since it has no removal date and it isn't hurting anything having it there.

  10. brettcannon
    added a commit that references this issue on Aug 8, 2025

    pythonGH-137426: Remove code deprecation of `importlib.abc.ResourceLo…

    d86f8b5
  11. brettcannon commented on Aug 8, 2025

    @brettcannon
    brettcannon
    on Aug 8, 2025
    Member
    More actions

    #137567 reverts the deprecation of ResourceLoader if that's the direction we choose to go.

    Reacted by Petr Viktorin
  12. brettcannon
    self-assigned this
    on Aug 8, 2025
  13. brettcannon
    added a commit that references this issue on Aug 11, 2025

    GH-137426: Remove code deprecation of `importlib.abc.ResourceLoader` (G…

    7140b99
  14. miss-islington
    added a commit that references this issue on Aug 11, 2025

    pythonGH-137426: Remove code deprecation of `importlib.abc.ResourceLo…

    fb6a8fa
  15. brettcannon commented on Aug 11, 2025

    @brettcannon
    brettcannon
    on Aug 11, 2025
    Member
    More actions

    This is now merged into main and awaiting Hugo to cherrypick into 3.14.

    Reacted by Terence Tsang
  16. TTsangSC commented on Aug 12, 2025

    @TTsangSC
    TTsangSC
    on Aug 12, 2025
    Author
    More actions

    Thanks for the fix!

  17. hugovk
    added a commit that references this issue on Aug 12, 2025

    [3.14] GH-137426: Remove code deprecation of `importlib.abc.ResourceL…

    daed07a
  18. hugovk commented on Aug 12, 2025

    @hugovk
    hugovk
    on Aug 12, 2025
    Member
    More actions

    Makes sense for this to be done for 3.14.0 and not 3.14.1, thanks all!

  19. hugovk
    closed this as completedon Aug 12, 2025
  20. github-project-automation
    moved this from Todo to Done in Release and Deferred blockers 🚫on Aug 12, 2025
  21. brettcannon commented on Aug 12, 2025

    @brettcannon
    brettcannon
    on Aug 12, 2025
    Member
    More actions

    @TTsangSC and thanks for testing the RC and reporting the bug!

    Reacted by Terence Tsang and Hugo van Kemenade
  22. maurycy
    added a commit that references this issue on Aug 12, 2025

    Merge branch 'main' into csv-sniffer-counter-set

    11c891d
  23. Agent-Hellboy
    added a commit that references this issue on Aug 19, 2025

    pythonGH-137426: Remove code deprecation of `importlib.abc.ResourceLo…

    d25273b
  24. kumaraditya303
    added a commit that references this issue on Sep 9, 2025

    [3.14] pythonGH-137426: Remove code deprecation of `importlib.abc.Res…

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

Metadata

Metadata

Assignees

  • @brettcannon
    brettcannon

Labels

3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixesrelease-blockerstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-importlibtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Projects

  • Release and Deferred blockers 🚫
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.