-
-
Notifications
You must be signed in to change notification settings - Fork 31k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
importlib.abc.Traversable.read_text()
incompatible with importlib.resources._functional.read_text()
usage (Python 3.13)
#127012
Comments
hey @kurtmckee I can work on this issue ...can you assign me. |
@kanishka-coder0809 As I wrote in the text above, I'd like to fix this myself but I'm waiting for confirmation how to proceed, because I think this issue implicates In any case, I don't have GitHub permissions to assign this to anyone. |
I'm encountering this issue while trying to add 3.13 support to PyTorch. |
Thanks Kurt for the detailed report elucidating the issue. I do think I agree that adding the required parameter to the default When reasoning about where to create the fix, I'm fine if it goes here or in At first, I was thinking that this change would be backward-incompatible, because it's a change to a protocol (on which downstream consumers rely), but since it's a change to a concrete method on the protocol, I'm thinking a backward-compatible change is possible, but we'll want to think carefully about that aspect of the change. Please feel free to proceed with a proposed fix. |
@jaraco Understood. I'll work to introduce a PR to the |
This adds an in-memory finder, loader, and traversable implementation, which allows the `Traversable` protocol and concrete methods to be tested. This additional infrastructure demonstrates python/cpython#127012, but also highlights that the `Traversable.joinpath()` concrete method raises `TraversalError` which is not getting caught in several places.
`importlib_resources.read_text()` calls the `Traversable.read_text()` concrete method with an `errors` argument that doesn't exist in the method signature, resulting in an `TypeError`. This is resolved by adding an `errors` parameter to `Traversable.read_text()`. Fixes python/cpython#127012
That's fine, but we also need to remove the call that passes it, since code already exists that can't receive the parameter. Changing the protocol requires a deprecation cycle and can't be backported. Adding a new (optional) method that also accepts |
@zooba I'm (possibly overly) cautious to take action without more direction. Should I submit a PR to this repo to remove the additional parameters from the call? Should I submit a separate PR to the I'm willing to do the work! I simply want to avoid botching something due to lack of experience in the |
A PR to |
This adds an in-memory finder, loader, and traversable implementation, which allows the `Traversable` protocol and concrete methods to be tested. This additional infrastructure demonstrates python/cpython#127012, but also highlights that the `Traversable.joinpath()` concrete method raises `TraversalError` which is not getting caught in several places.
Re-opening to track the merge from importlib_resources to cpython. |
|
….4.5 to version 6.5.2 Anderson Bravalheri (1): Bump pre-commit hook for ruff to avoid clashes with pytest-ruff (jaraco/skeleton#150) Avasam (1): Fix an incompatibility (and source of merge conflicts) with projects using Ruff/isort. Jason R. Coombs (26): Remove workaround for sphinx-contrib/sphinx-lint#83 Allow the workflow to be triggered manually. Add Python 3.13 and 3.14 into the matrix. (jaraco/skeleton#146) Add workaround for broken importlib.resources when an editable sentinel is present. Separate bpo from Python issue numbers. gh-123994: Generate utf-16 file using little endian and BOM. (#123995) 👹 Feed the hobgoblins (delint). Add Python 3.13 and 3.14 into the matrix. (jaraco/skeleton#151) Include pyproject.toml in ruff.toml. Require Python 3.9 or later now that Python 3.8 is EOL. Use extend for proper workaround. 👹 Feed the hobgoblins (delint). Remove unused imports. Bump badge for 2025. Re-enable type checks. Apply import sort fixers from ruff. Add type annotations for Traversable.open. Remove Python 3.8 compatibility code. Finalize Consolidate MemoryTraversable._resolve. Replace unreachable block with simple assertion. Fixes diffcov failure. Add news fragment. Finalize Rely on Literal from stdlib. Add news fragment. Finalize Kurt McKee (3): Demonstrate python/cpython#127012 Catch `TraversalError`, raised by `Traversable.joinpath()` Resolve a `TypeError` lurking in the `read_text()` functional API Peter St. John (2): Add typing-extensions as a dependency Update pyproject.toml Petr Viktorin (1): gh-123085: _compile_importlib: Avoid copying sources before compilation (GH-124131)
Bug report
Bug description:
I'm writing a custom importer and discovered that the function signature for
importlib.abc.Traversable.read_text()
is incompatible with the usage inimportlib.resources._functional.read_text()
, specifically on Python 3.13.importlib.abc.Traversable.read_text()
is a concrete method; its implementation calls the.open()
method, which is an abstract method that must be implemented. The expectation is therefore that implementing.open()
in a Traversable subclass is sufficient for.read_text()
to work.Note below that the
.read_text()
method is not marked as abstract, and includes only one parameter:encoding
:cpython/Lib/importlib/resources/abc.py
Lines 84 to 90 in 30aeb00
Application code that attempts to read a package resource, like
importlib.resources.read_text(module, "resource.txt")
ultimately leads to a call toimportlib.resources._functional.read_text()
, which attempts to call the.read_text()
method of a Traversable subclass, but includes anerrors
parameter that doesn't exist in Traversable's default concrete method:cpython/Lib/importlib/resources/_functional.py
Lines 28 to 32 in 30aeb00
Consequently, it appears to be necessary for all Traversable subclasses to not only re-implement its concrete
.read_text()
method, but also to override its signature.I think that the Traversable
.read_text()
method signature, and the call site inimportlib.resources._functional.read_text()
, need to align with each other.I'd like to submit a PR for this! However, I would like confirmation that an
errors
parameter should be added to theTraversable.read_text()
method.Note that adding an
errors
parameter was previously discussed in #88368.Demonstration of TypeError bug
CPython versions tested on:
3.13
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: