Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Different output from importlib.resources.files() in REPL in 3.12 versus 3.13 #121190

Copy link
Copy link
Open
@danielhollas

Description

@danielhollas
Issue body actions

Bug report

Bug description:

Running importlib.resources.files() without specifying the anchor parameter in interactive REPL in Python 3.12 raises a rather unhelpful error:

>>> import importlib.resources
>>> importlib.resources.files()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python3.12/importlib/resources/_common.py", line 45, in wrapper
    return func()
           ^^^^^^
  File "/usr/lib64/python3.12/importlib/resources/_common.py", line 56, in files
    return from_package(resolve(anchor))
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/resources/_common.py", line 113, in from_package
    reader = spec.loader.get_resource_reader(spec.name)
                                             ^^^^^^^^^
  File "/usr/lib64/python3.12/importlib/resources/_adapters.py", line 17, in __getattr__
    return getattr(self.spec, name)
           ^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'name'

It would be nice to return something more helpful. The documentation doesn't mention that this function can raise, so I am assuming that raising AttributeError is not part of the public API?

However, on a locally built Python from current main branch, this call returns a path to Lib/_pyrepl. Even more surprising though is that this also happens when running the OLD REPL with TERM=dumb ./python

TERM=dumb ./python 
Python 3.14.0a0 (heads/main:1a84bdc237, Jun 30 2024, 21:44:46) [GCC 13.3.1 20240522 (Red Hat 13.3.1-1)] on linux
Type "help", "copyright", "credits" or "license" for more information.
warning: can't use pyrepl: terminal doesn't have the required clear capability
>>> import importlib.resources
>>> importlib.resources.files()
PosixPath('/home/hollas/software/cpython/Lib/_pyrepl')

CPython versions tested on:

3.12, CPython main branch

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirPython modules in the Lib dirtopic-replRelated to the interactive shellRelated to the interactive shelltype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.