Use importlib_metadata for Python < 3.10.2#693
Merged
Conversation
henryiii
reviewed
Oct 17, 2023
henryiii
reviewed
Oct 17, 2023
henryiii
approved these changes
Oct 17, 2023
src/build/_importlib.py
Outdated
| import importlib_metadata as metadata | ||
| elif sys.version_info < (3, 9, 10) or (3, 10, 0) <= sys.version_info < (3, 10, 2): | ||
| if sys.version_info >= (3, 10, 2): | ||
| from importlib import metadata # type: ignore[attr-defined] |
Contributor
Author
There was a problem hiding this comment.
The type: ignore workaround is needed to pass the "type" job https://github.com/pypa/build/actions/runs/6558894339/job/17813388696?pr=693
I didn't find a better way 🤔
Contributor
There was a problem hiding this comment.
Something like this?
if sys.version_info < (3, 8):
import importlib_metadata as metadata
elif sys.version_info >= (3, 10, 2):
from importlib import metadata
else:
try:
import importlib_metadata as metadata
except ModuleNotFoundError:
# helps bootstrapping when dependencies aren't installed
from importlib import metadata
Contributor
Author
There was a problem hiding this comment.
Yes this worked, thanks (side note, I'm surprised that mypy still raises an error when the the order of the first two conditions is inverted)
5fd5f44 to
52f11f2
Compare
henryiii
approved these changes
Oct 19, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #692.