Skip to content
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

Use importlib_metadata for Python < 3.10.2 #693

Merged
merged 5 commits into from Oct 27, 2023

Conversation

GianlucaFicarelli
Copy link
Contributor

Closes #692.

pyproject.toml Outdated Show resolved Hide resolved
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]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🤔

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

@henryiii henryiii merged commit e3081b6 into pypa:main Oct 27, 2023
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants