Skip to content

Commit 7d27b9c

Browse files
committed
Fix various typing errors on Windows
1 parent e0c7f24 commit 7d27b9c

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

tests/lib/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,14 +266,14 @@ def __getattr__(self, attr: str) -> Any:
266266
if sys.platform == "win32":
267267

268268
@property
269-
def stdout(self):
269+
def stdout(self) -> str:
270270
return self._impl.stdout.replace("\r\n", "\n")
271271

272272
@property
273-
def stderr(self):
273+
def stderr(self) -> str:
274274
return self._impl.stderr.replace("\r\n", "\n")
275275

276-
def __str__(self):
276+
def __str__(self) -> str:
277277
return str(self._impl).replace("\r\n", "\n")
278278

279279
else:
@@ -618,7 +618,7 @@ def run(
618618
cwd = cwd or self.cwd
619619
if sys.platform == "win32":
620620
# Partial fix for ScriptTest.run using `shell=True` on Windows.
621-
args = [str(a).replace("^", "^^").replace("&", "^&") for a in args]
621+
args = tuple(str(a).replace("^", "^^").replace("&", "^&") for a in args)
622622

623623
if allow_error:
624624
kw["expect_error"] = True

tests/lib/server.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from .compat import nullcontext
1515

1616
if TYPE_CHECKING:
17-
from wsgi import StartResponse, WSGIApplication, WSGIEnvironment
17+
from _typeshed.wsgi import StartResponse, WSGIApplication, WSGIEnvironment
1818

1919
Body = Iterable[bytes]
2020

@@ -23,7 +23,7 @@ class MockServer(BaseWSGIServer):
2323
mock: Mock = Mock()
2424

2525

26-
# Applies on Python 2 and Windows.
26+
# Applies on Windows.
2727
if not hasattr(signal, "pthread_sigmask"):
2828
# We're not relying on this behavior anywhere currently, it's just best
2929
# practice.
@@ -41,11 +41,17 @@ def blocked_signals() -> Iterator[None]:
4141
except AttributeError:
4242
mask = set(range(1, signal.NSIG))
4343

44-
old_mask = signal.pthread_sigmask(signal.SIG_SETMASK, mask)
44+
old_mask = signal.pthread_sigmask( # type: ignore[attr-defined]
45+
signal.SIG_SETMASK, # type: ignore[attr-defined]
46+
mask,
47+
)
4548
try:
4649
yield
4750
finally:
48-
signal.pthread_sigmask(signal.SIG_SETMASK, old_mask)
51+
signal.pthread_sigmask( # type: ignore[attr-defined]
52+
signal.SIG_SETMASK, # type: ignore[attr-defined]
53+
old_mask,
54+
)
4955

5056

5157
class _RequestHandler(WSGIRequestHandler):

tests/unit/test_appdirs.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ def test_user_cache_dir_unicode(self, monkeypatch: pytest.MonkeyPatch) -> None:
6565
def my_get_win_folder(csidl_name: str) -> str:
6666
return "\u00DF\u00E4\u03B1\u20AC"
6767

68-
monkeypatch.setattr(platformdirs.windows, "get_win_folder", my_get_win_folder)
68+
monkeypatch.setattr(
69+
platformdirs.windows, # type: ignore[attr-defined]
70+
"get_win_folder",
71+
my_get_win_folder,
72+
)
6973

7074
# Do not use the isinstance expression directly in the
7175
# assert statement, as the Unicode characters in the result

tests/unit/test_locations.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,9 @@ def patch(self) -> None:
5151
# now patch
5252
tempfile.gettempdir = lambda: self.tempdir
5353
getpass.getuser = lambda: self.username
54-
os.geteuid = lambda: self.st_uid
5554
os.fstat = lambda fd: self.get_mock_fstat(fd)
56-
5755
if sys.platform != "win32":
56+
os.geteuid = lambda: self.st_uid
5857
pwd.getpwuid = self.get_mock_getpwuid
5958

6059
def revert_patch(self) -> None:

0 commit comments

Comments
 (0)