Skip to content

Fix pyinfo for Python 3.12 changes #15103

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

Merged
merged 2 commits into from
Apr 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions mypy/pyinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
library found in Python 3.7. This file is run each mypy run, so it should be kept as fast as
possible.
"""
import os
import site
import sys
import sysconfig

if __name__ == "__main__":
# HACK: We don't want to pick up mypy.types as the top-level types
Expand All @@ -22,6 +19,10 @@

sys.path = old_sys_path

import os
import site
import sysconfig
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

sysconfig now imports types, so we need to do the path hack sooner



def getsitepackages() -> list[str]:
res = []
Expand All @@ -31,9 +32,7 @@ def getsitepackages() -> list[str]:
if hasattr(site, "getusersitepackages") and site.ENABLE_USER_SITE:
res.insert(0, site.getusersitepackages())
else:
from distutils.sysconfig import get_python_lib

res = [get_python_lib()]
res = [sysconfig.get_paths()["purelib"]]
Copy link
Member

Choose a reason for hiding this comment

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

Something I don't recall, are purelib and sitepackages 1-to-1? I also don't recall if platdir is included in getsitepackages.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yeah, I think what I have is equivalent to get_python_lib, but I think you're right that platlibdir is in getsitepackages

return res


Expand Down