Skip to content

Commit 0c68ed1

Browse files
Several typecheck improvements related to mypy 0.941.
This changes the way we test for specific platforms according to what mypy understands and it runs mypy in CI against all platforms (linux/win32/darwin).
1 parent fe50f11 commit 0c68ed1

File tree

17 files changed

+85
-57
lines changed

17 files changed

+85
-57
lines changed

.github/workflows/test.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ jobs:
3232
# Check wheather the imports were sorted correctly.
3333
# When this fails, please run ./tools/sort-imports.sh
3434
run: |
35-
mypy --strict prompt_toolkit
35+
mypy --strict prompt_toolkit --platform win32
36+
mypy --strict prompt_toolkit --platform linux
37+
mypy --strict prompt_toolkit --platform darwin
3638
isort -c --profile black prompt_toolkit examples tests setup.py
3739
black --check prompt_toolkit examples tests setup.py
3840
- name: Validate README.md

mypy.ini

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
[mypy]
2-
platform = win32
3-
42
# --strict.
53
check_untyped_defs = True
64
disallow_any_generics = True

prompt_toolkit/application/application.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@
8989
)
9090
from prompt_toolkit.utils import Event, in_main_thread
9191

92-
from ..utils import is_windows
9392
from .current import get_app_session, set_app
9493
from .run_in_terminal import in_terminal, run_in_terminal
9594

@@ -663,7 +662,7 @@ async def run_async(
663662
"""
664663
assert not self._is_running, "Application is already running."
665664

666-
if not in_main_thread() or is_windows():
665+
if not in_main_thread() or sys.platform == "win32":
667666
# Handling signals in other threads is not supported.
668667
# Also on Windows, `add_signal_handler(signal.SIGINT, ...)` raises
669668
# `NotImplementedError`.

prompt_toolkit/eventloop/inputhook.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,12 @@
2626
import os
2727
import select
2828
import selectors
29+
import sys
2930
import threading
3031
from asyncio import AbstractEventLoop
3132
from selectors import BaseSelector, SelectorKey
3233
from typing import TYPE_CHECKING, Any, Callable, List, Mapping, Optional, Tuple
3334

34-
from prompt_toolkit.utils import is_windows
35-
3635
from .utils import get_event_loop
3736

3837
__all__ = [
@@ -141,7 +140,7 @@ def input_is_ready() -> bool:
141140
# However, if we would ever want to add a select call, it
142141
# should use `windll.kernel32.WaitForMultipleObjects`,
143142
# because `select.select` can't wait for a pipe on Windows.
144-
if not is_windows():
143+
if sys.platform != "win32":
145144
select.select([self._r], [], [], None)
146145

147146
os.read(self._r, 1024)

prompt_toolkit/eventloop/win32.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import sys
2+
3+
assert sys.platform == "win32"
4+
15
from ctypes import pointer
26

37
from ..utils import SPHINX_AUTODOC_RUNNING

prompt_toolkit/input/defaults.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import sys
22
from typing import ContextManager, Optional, TextIO
33

4-
from prompt_toolkit.utils import is_windows
5-
64
from .base import DummyInput, Input, PipeInput
75

86
__all__ = [
@@ -23,7 +21,7 @@ def create_input(
2321
`sys.stdin`. (We can open `stdout` or `stderr` for reading, this is how
2422
a `$PAGER` works.)
2523
"""
26-
if is_windows():
24+
if sys.platform == "win32":
2725
from .win32 import Win32Input
2826

2927
# If `stdin` was assigned `None` (which happens with pythonw.exe), use
@@ -61,7 +59,7 @@ def create_pipe_input() -> ContextManager[PipeInput]:
6159
Breaking change: In prompt_toolkit 3.0.28 and earlier, this was returning
6260
the `PipeInput` directly, rather than through a context manager.
6361
"""
64-
if is_windows():
62+
if sys.platform == "win32":
6563
from .win32_pipe import Win32PipeInput
6664

6765
return Win32PipeInput.create()

prompt_toolkit/input/posix_pipe.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import sys
2+
3+
assert sys.platform != "win32"
4+
15
import os
26
from contextlib import contextmanager
37
from typing import ContextManager, Iterator, TextIO, cast

prompt_toolkit/input/vt100.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
import sys
2+
3+
assert sys.platform != "win32"
4+
15
import contextlib
26
import io
3-
import sys
47
import termios
58
import tty
69
from asyncio import AbstractEventLoop

prompt_toolkit/input/win32.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from ..utils import SPHINX_AUTODOC_RUNNING
99

10+
assert sys.platform == "win32"
11+
1012
# Do not import win32-specific stuff when generating documentation.
1113
# Otherwise RTD would be unable to generate docs for this module.
1214
if not SPHINX_AUTODOC_RUNNING:

prompt_toolkit/input/win32_pipe.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import sys
2+
3+
assert sys.platform == "win32"
4+
15
from contextlib import contextmanager
26
from ctypes import windll
37
from ctypes.wintypes import HANDLE

0 commit comments

Comments
 (0)