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 — Remove deprecation notes for non-deprecated `importlib.resources` functions · Issue #139344 · python/cpython

Remove deprecation notes for non-deprecated importlib.resources functions #139344

New issue
Copy link
New issue
Copy link
Closed
Closed
Remove deprecation notes for non-deprecated importlib.resources functions#139344
Copy link
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-importlib

Description

@Timmmm
Timmmm
opened on Sep 26, 2025
Issue body actions

I wrote some code using read_text() and a few other functions from importlib and was surprised that Pylint complained they are deprecated. There's no mention of that in the documentation.

Eventually I discovered that the Python 3.13 release notes claim that they are "pending removal" as if they've already been deprecated.

It links to this note which says that files() is "preferred", but are the old methods really deprecated? Are they really going to be removed?

Seems kind of insane to me. The suggested alternative to read_text() is to copy all this code into your project:

def read_text(
    package: Package,
    resource: Resource,
    encoding: str = 'utf-8',
    errors: str = 'strict',
) -> str:
    """Return the decoded string of the resource.

    The decoding-related arguments have the same semantics as those of
    bytes.decode().
    """
    with open_text(package, resource, encoding, errors) as fp:
        return fp.read()

def open_text(
    package: Package,
    resource: Resource,
    encoding: str = 'utf-8',
    errors: str = 'strict',
) -> TextIO:
    """Return a file-like object opened for text reading of the resource."""
    return (_common.files(package) / _common.normalize_path(resource)).open(
        'r', encoding=encoding, errors=errors
    )

def files(package):
    # type: (Package) -> Traversable
    """
    Get a Traversable resource from a package
    """
    return from_package(get_package(package))


def normalize_path(path):
    # type: (Any) -> str
    """Normalize a path by ensuring it is a string.

    If the resulting string contains path separators, an exception is raised.
    """
    str_path = str(path)
    parent, file_name = os.path.split(str_path)
    if parent:
        raise ValueError(f'{path!r} must be only a file name')
    return file_name


def get_resource_reader(package):
    # type: (types.ModuleType) -> Optional[ResourceReader]
    """
    Return the package's loader if it's a ResourceReader.
    """
    # We can't use
    # a issubclass() check here because apparently abc.'s __subclasscheck__()
    # hook wants to create a weak reference to the object, but
    # zipimport.zipimporter does not support weak references, resulting in a
    # TypeError.  That seems terrible.
    spec = package.__spec__
    reader = getattr(spec.loader, 'get_resource_reader', None)  # type: ignore
    if reader is None:
        return None
    return reader(spec.name)  # type: ignore


def resolve(cand):
    # type: (Package) -> types.ModuleType
    return cand if isinstance(cand, types.ModuleType) else importlib.import_module(cand)


def get_package(package):
    # type: (Package) -> types.ModuleType
    """Take a package name or module object and return the module.

    Raise an exception if the resolved module is not a package.
    """
    resolved = resolve(package)
    if wrap_spec(resolved).submodule_search_locations is None:
        raise TypeError(f'{package!r} is not a package')
    return resolved


def from_package(package):
    """
    Return a Traversable object for the given package.

    """
    spec = wrap_spec(package)
    reader = spec.loader.get_resource_reader(spec.name)
    return reader.files()

Linked PRs

  • gh-139344: Remove pending removal notice for undeprecated importlib.resources API #141507
  • [3.13] gh-139344: Remove pending removal notice for undeprecated importlib.resources API (GH-141507) #141557
  • [3.14] gh-139344: Remove pending removal notice for undeprecated importlib.resources API (GH-141507) #141558

Activity

  1. Timmmm
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Sep 26, 2025
  2. github-project-automation
    added this to docs issueson Sep 26, 2025
  3. github-project-automation
    moved this to Todo in docs issueson Sep 26, 2025
  4. picnixz commented on Sep 26, 2025

    @picnixz
    picnixz
    on Sep 26, 2025
    Member
    More actions

    Actually, they were deprecated in #106532 and then un-deprecated, but I think we forgot to remove the mention of them being deprecated in #116608.

    cc @jaraco @graingert

    Reacted by Tim Hutt
    Reacted by Pierre Sassoulas
  5. picnixz
    added
    topic-importlib
    on Sep 26, 2025
  6. picnixz
    changed the title [-]Are importlib.read_text etc. really deprecated?[/-] [+]Remove deprecation notes for non-deprecated `importlib.resources` functions[/+] on Sep 26, 2025
  7. gpshead commented on Nov 11, 2025

    @gpshead
    gpshead
    on Nov 11, 2025
    Member
    More actions

    cc @encukou

  8. encukou
    added a commit that references this issue on Nov 13, 2025

    pythongh-139344: Remove pending removal notice for undeprecated impor…

    9d67b76
  9. encukou commented on Nov 13, 2025

    @encukou
    encukou
    on Nov 13, 2025
    Member
    More actions

    Thanks for the catch! They've indeed been un-deprecated.

    Reacted by Tim Hutt
  10. encukou
    added a commit that references this issue on Nov 14, 2025

    gh-139344: Remove pending removal notice for undeprecated importlib.r…

    49e7421
  11. miss-islington
    added 2 commits that reference this issue on Nov 14, 2025

    pythongh-139344: Remove pending removal notice for undeprecated impor…

    ee4dbec

    pythongh-139344: Remove pending removal notice for undeprecated impor…

    ade5498
  12. encukou
    added 2 commits that reference this issue on Nov 14, 2025

    [3.14] gh-139344: Remove pending removal notice for undeprecated impo…

    2f23c88

    [3.13] gh-139344: Remove pending removal notice for undeprecated impo…

    9648eed
  13. hugovk
    closed this as completedon Nov 17, 2025
  14. StanFromIreland
    added a commit that references this issue on Dec 6, 2025

    pythongh-139344: Remove pending removal notice for undeprecated impor…

    9f76a14
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

    docsDocumentation in the Doc dirDocumentation in the Doc dirtopic-importlib

    Projects

    • docs issues
      Status
      Todo
      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.