Skip to content

Commit f6a33b3

Browse files
committed
Fix mypy checks on Windows
Previously we were making unguarded calls to non-Windows-only APIs. Mypy only automatically excludes these from platform-specific checks when inside conditions.
1 parent c9ab34a commit f6a33b3

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

src/pip/_internal/utils/compat.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -257,12 +257,13 @@ def ioctl_GWINSZ(fd):
257257
return cr
258258
cr = ioctl_GWINSZ(0) or ioctl_GWINSZ(1) or ioctl_GWINSZ(2)
259259
if not cr:
260-
try:
261-
fd = os.open(os.ctermid(), os.O_RDONLY)
262-
cr = ioctl_GWINSZ(fd)
263-
os.close(fd)
264-
except Exception:
265-
pass
260+
if sys.platform != "win32":
261+
try:
262+
fd = os.open(os.ctermid(), os.O_RDONLY)
263+
cr = ioctl_GWINSZ(fd)
264+
os.close(fd)
265+
except Exception:
266+
pass
266267
if not cr:
267268
cr = (os.environ.get('LINES', 25), os.environ.get('COLUMNS', 80))
268269
return int(cr[1]), int(cr[0])

src/pip/_internal/utils/filesystem.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import random
55
import shutil
66
import stat
7+
import sys
78
from contextlib import contextmanager
89
from tempfile import NamedTemporaryFile
910

@@ -29,7 +30,7 @@ def check_path_owner(path):
2930
# type: (str) -> bool
3031
# If we don't have a way to check the effective uid of this process, then
3132
# we'll just assume that we own the directory.
32-
if not hasattr(os, "geteuid"):
33+
if sys.platform == "win32" or not hasattr(os, "geteuid"):
3334
return True
3435

3536
previous = None

src/pip/_internal/utils/glibc.py

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os
77
import re
8+
import sys
89
import warnings
910

1011
from pip._internal.utils.typing import MYPY_CHECK_RUNNING
@@ -26,6 +27,8 @@ def glibc_version_string_confstr():
2627
# to be broken or missing. This strategy is used in the standard library
2728
# platform module:
2829
# https://github.com/python/cpython/blob/fcf1d003bf4f0100c9d0921ff3d70e1127ca1b71/Lib/platform.py#L175-L183
30+
if sys.platform == "win32":
31+
return None
2932
try:
3033
# os.confstr("CS_GNU_LIBC_VERSION") returns a string like "glibc 2.17":
3134
_, version = os.confstr("CS_GNU_LIBC_VERSION").split()

0 commit comments

Comments
 (0)