-
-
Notifications
You must be signed in to change notification settings - Fork 2.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.readers not valid until python 3.10 #9609
Changes from all commits
15ddccf
5f1a2f3
66dc79e
f86a87a
d45a19c
2073cce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fix invalid importing of ``importlib.readers`` in Python 3.9. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -273,13 +273,15 @@ def get_data(self, pathname: Union[str, bytes]) -> bytes: | |
with open(pathname, "rb") as f: | ||
return f.read() | ||
|
||
if sys.version_info >= (3, 9): | ||
if sys.version_info >= (3, 10): | ||
|
||
def get_resource_reader(self, name: str) -> importlib.abc.TraversableResources: # type: ignore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey, I'm currently writing a code analysis tool for Python projects. It pointed me to this code part, which I find quite interesting. Hence, I would have some questions about it:
I think these questions may be adressed to @kdelee or @nicoddemus? I would be really happy to hear from you as this would give me some qualitative insights on the reports of my tool. Kind regards, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's called by the python import machinery itself. this function isn't valid until 3.10 (it breaks 3.9) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I saw the Github issue on the FileReader import causing the break for 3.9 Before, the import statement in the function was without any version check. But having the check There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there's backports of parts of importlib which would reach into this and if the function is defined try and call it (and then error) -- by not defining the function, those backports won't even attempt to call it and therefore won't crash There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ahh ok I understand. Thanky you very much for your explanation, this helps me a lot! |
||
from types import SimpleNamespace | ||
from importlib.readers import FileReader | ||
if sys.version_info < (3, 11): | ||
from importlib.readers import FileReader | ||
else: | ||
from importlib.resources.readers import FileReader | ||
|
||
return FileReader(SimpleNamespace(path=self._rewritten_names[name])) | ||
return FileReader(types.SimpleNamespace(path=self._rewritten_names[name])) | ||
|
||
|
||
def _write_pyc_fp( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that this should be changed to
(3, 10)
sinceFileReader
isn't needed there