-
-
Notifications
You must be signed in to change notification settings - Fork 30.5k
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
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 |
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: