Skip to content

Commit e516865

Browse files
Resolve symlinks in getsyspath() stdlib exclusion
1 parent b69b434 commit e516865

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

mypy/pyinfo.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,10 @@ def getsyspath() -> list[str]:
4747
)
4848
stdlib = sysconfig.get_path("stdlib")
4949
stdlib_ext = os.path.join(stdlib, "lib-dynload")
50-
excludes = {stdlib_zip, stdlib, stdlib_ext}
50+
# Resolve symlinks: base_exec_prefix / sysconfig paths retain the symlink
51+
# form (e.g. Homebrew's /opt/homebrew/opt/python@3.13) while sys.path
52+
# entries arrive pre-resolved by Python. See python/mypy#21474.
53+
excludes = {os.path.realpath(p) for p in (stdlib_zip, stdlib, stdlib_ext)}
5154

5255
# Drop the first entry of sys.path
5356
# - If pyinfo.py is executed as a script (in a subprocess), this is the directory
@@ -63,7 +66,7 @@ def getsyspath() -> list[str]:
6366
offset = 0 if sys.version_info >= (3, 11) and sys.flags.safe_path else 1
6467

6568
abs_sys_path = (os.path.abspath(p) for p in sys.path[offset:])
66-
return [p for p in abs_sys_path if p not in excludes]
69+
return [p for p in abs_sys_path if os.path.realpath(p) not in excludes]
6770

6871

6972
def getsearchdirs() -> tuple[list[str], list[str]]:

0 commit comments

Comments
 (0)