| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
…es() when module spec is not available
There was a problem hiding this comment.
Thanks for working on this! 👏
Sorry, something went wrong.
|
|
||
| TYPE_CHECKING = False | ||
| if TYPE_CHECKING: | ||
| from ..machinery import ModuleSpec |
There was a problem hiding this comment.
Python stdlib is not typed (that's what typeshed is for) so you'll likely be asked to revert these changes
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, please revert all type annotation changes.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks updated!
Sorry, something went wrong.
|
|
||
| spec = wrap_spec(package) | ||
| if package.__spec__ is None: | ||
| raise TypeError(f"Can't access resources on a module with no spec: {package}") |
There was a problem hiding this comment.
I wonder is the error can be a bit more specific. I think most Python users will not know what a "spec" is? (I don't :-) )
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks. I proposed a new message. wdyt?
Sorry, something went wrong.
| Adapt a package spec to adapt the underlying loader. | ||
| """ | ||
|
|
||
| def __init__(self, spec, adapter=lambda spec: spec.loader): |
There was a problem hiding this comment.
Why was the default adapter removed? Isn't this a breaking change?
Sorry, something went wrong.
There was a problem hiding this comment.
For the simplicity sake, because it seems not to be used anywhere.
This default value was defined since this mechanism was introduced in #24670 but it was not used even in that commit.
Sorry, something went wrong.
There was a problem hiding this comment.
As it does not pertain to the issue that's addressed in this PR I'd recommend reverting this change anyway.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks, got it 👍
Sorry, something went wrong.
There was a problem hiding this comment.
By the way, importlib.resources module is somewhat special as its development is mainly in importlib_resources package which is then backported here, see https://github.com/python/importlib_metadata/wiki/Development-Methodology
So I am not sure if this PR should be merged here or moved over to the importlib_resources repo (CC @jaraco)
Sorry, something went wrong.
| Adapt a package spec to adapt the underlying loader. | ||
| """ | ||
|
|
||
| def __init__(self, spec, adapter=lambda spec: spec.loader): |
There was a problem hiding this comment.
As it does not pertain to the issue that's addressed in this PR I'd recommend reverting this change anyway.
Sorry, something went wrong.
It can be merged here, but we prefer to merge changes in importlib_resources to make it easier to keep the code in sync. |
Sorry, something went wrong.
There was a problem hiding this comment.
Sorry, something went wrong.
Co-authored-by: Daniel Hollas <danekhollas@gmail.com>
|
Thank you, I created a PR to python/importlib_resources as well: python/importlib_resources#331 |
Sorry, something went wrong.
|
Thanks for this change. I made some changes in the importlib_resources port, so I'd rather apply that here. This work will happen in gh-148460. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
importlib.resources.files(package) raises an error when package.__spec__ is None because the code below refers to spec.name but spec is None.
cpython/Lib/importlib/resources/_common.py
Line 117 in f19f1d8
The error would be
and #121190 said it's not helpful.
This PR adds a None-check to handle such a case and raise an error with a specific message.
(This is from PyConTW 2025 sprint)