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

Avoid _distutils_hack.remove_shim on Python >= 3.12 #3952

Merged
merged 5 commits into from Jun 19, 2023

Conversation

abravalheri
Copy link
Contributor

@abravalheri abravalheri commented Jun 12, 2023

In #3952 we learned that _distutils_hack may cause problems in Python 3.12 when pip is imported.

Summary of changes

_distutils_hack should not be disabled on Python >= 3.12
In this PR we:

Closes #3661

Pull Request Checklist

@abravalheri abravalheri marked this pull request as ready for review June 13, 2023 12:28


def insert_shim():
sys.meta_path.insert(0, DISTUTILS_FINDER)


def remove_shim():
def _remove_shim():
Copy link
Member

Choose a reason for hiding this comment

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

This whole module is private, so it's probably not necessary to mark it private, but also no problem if it is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you Jason. The renaming of the function was inspired by this piece of code in pip:

try:
    __import__("_distutils_hack").remove_shim()
except (ImportError, AttributeError):
    pass

Due to the rename the call would fail with an AttributeError that would be simply ignored. Without the renaming, there is some change of the importer being disable on Python >= 3.12.

@abravalheri abravalheri merged commit 718493c into pypa:main Jun 19, 2023
23 checks passed
@vstinner
Copy link
Contributor

Thank you for the fix!

@abravalheri abravalheri deleted the issue-3661 branch June 19, 2023 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] distutils cannot be imported on Python 3.12 (without distutils) if pip was imported
3 participants