Skip to content

Commit 8f48f1b

Browse files
authored
Fix --package-root tests for Windows and Python 3.13+ (#19583)
This PR should fix the rest of the test failures in #19545. A change to `os.path.relpath` in 3.13 seems to have broken the handling of Windows paths beginning with `\\`. To resolve this issue, we don't split the drive letter off of the path and instead verify the path is on the current drive. If it isn't it will never resolve to the package root because that must be on the same drive as the CWD: https://github.com/python/mypy/blob/5b03024e829940cf3c3e3d99fc6625f569d02728/mypy/main.py#L1571-L1572 Keeping the drive letter allows relpath to properly generate a relative path and make the tests pass. I need to investigate if the relpath change is a regression in CPython.
1 parent 1c48286 commit 8f48f1b

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

mypy/fscache.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,12 @@ def init_under_package_root(self, path: str) -> bool:
117117
if not stat.S_ISDIR(st.st_mode):
118118
return False
119119
ok = False
120-
drive, path = os.path.splitdrive(path) # Ignore Windows drive name
120+
121+
# skip if on a different drive
122+
current_drive, _ = os.path.splitdrive(os.getcwd())
123+
drive, _ = os.path.splitdrive(path)
124+
if drive != current_drive:
125+
return False
121126
if os.path.isabs(path):
122127
path = os.path.relpath(path)
123128
path = os.path.normpath(path)

0 commit comments

Comments
 (0)