-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Possible regression in MultiplexedPath.joinpath in 3.12 #106614
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
Comments
One question. The demo you gave is |
This use-case wasn't considered. It wasn't intentional to break existing supported use-cases, but this case also wasn't tested and so thus isn't explicitly supported. This change was first introduced in python/importlib_resources#250. The intent was to provide a generic, re-usable implementation of What is meant by Looking at your example, I'm guessing you're using
Of course, if what you need is a tree of resources, you'll need |
No, it's not, sorry. I was testing multiple scenarios and copied a different one than intended. The one with
Thank you for the detailed explanation. The code using Traversable this way isn't mine. I've just needed to fix it to make that compatible with Python 3.12 during mass package rebuild in Fedora.
I can only guess here because I'm not the original author of the code I needed to fix. But yes, calling
And the code I'm referring to uses
That sounds reasonable but
Is there any nicer and more readable solution than |
FTR: It seems that the same problem was reported in python/importlib_resources#263 From the issue, it seems that another possible workaround without accessing the internal attribute of |
Thanks for the ping - I'd lost track of the issue.
Aah. yes. My mistake. 🤦 I'd forgotten that If you're willing to assume that your resource providers are always providing resources that are present in one package on the file system and that cleanup will never be necessary, you could enter the context and never exit:
Here's a real-world example (not recommended) of a project abusing the context manager to ensure that the data is present on the file system for the duration of the process. However, in python/importlib_resources#286, I learned that you have a namespace package and thus you get a
As you can see illustrated above, the fact that This technique wouldn't work if the resource you desire is present in a later package:
That's why MultiplexedPath exists - to honor resources that may exist across one or more paths. But I suspect what's happening is you're not intending or expecting to get a namespace package or multiplexed path, but instead, you're happening to get one because you're accessing When you specify And because Python will magically import any directory as a namespace package, that's why you're getting the namespace package and the MultiplexedPath.
My guess is if you instead were to use
(and you could I think the real question here is - what are you trying to accomplish with The only safe way to access a Traversable is to use its limited interface or rely on |
Thank you very much for the detailed explanation. I think this issue can be closed now. |
Bug report
In Python 3.11, it's possible to use
MultiplexedPath.joinpath("")
(with an empty argument) and it returns the first path stored inMultiplexedPath._paths
, for example:But in Python 3.12, this doesn't work anymore:
The implementation has been changed in: cea910e#diff-2e741d925220d74a9cc04cda1314d3649d9d189c0efc7db18e5387a51225b61c
Your environment
Python 3.12 beta 3 installed from Fedora RPM, Fedora 38, x86_64
The text was updated successfully, but these errors were encountered: