Add example of using importlib.resources.files() in Python 3.12
This was a helpful example repo. I just have one request.
In Python 3.12 they updated importlib.resources.files(): https://docs.python.org/3/library/importlib.resources.html#importlib.resources.files
Changed in version 3.12: package parameter was renamed to anchor. anchor can now be a non-package module and if omitted will default to the caller’s module. package is still accepted for compatibility but will raise a DeprecationWarning. Consider passing the anchor positionally or using importlib_resources >= 5.10 for a compatible interface on older Pythons.
Could you include an example of omitting anchor so that it defaults to the caller’s module (or explicitly passing the module name with a string literal or __name__? I tried myself and while it works before packaging with zipapp, it fails to open and read the data file when running the zip. I'm not sure if I'm doing something wrong.
It looks like this new feature is buggy. I get FileNotFoundError("Can't open orphan path") when trying to use that technique within a zipapp. Are you seeing the same error message?
Yes I see that too. I wasn't sure if it was just buggy since it's a relatively new feature or if I didn't understand something.
If you also think this is a bug, I will file an issue with cpython.
It’s either a bug or a footgun that ought to be documented.
Created issue https://github.com/python/cpython/issues/121735
In https://github.com/wimglenn/resources-example/blob/8384ded77a3711155b2b3508f3f473207fffddcb/myapp/example5.py#L8-L10 I've added a note advising to avoid this usage until the zipapp issue is fixed.