diff --git a/Lib/_pyrepl/commands.py b/Lib/_pyrepl/commands.py index 503ca1da329eaa..ca1d29b125252c 100644 --- a/Lib/_pyrepl/commands.py +++ b/Lib/_pyrepl/commands.py @@ -32,8 +32,8 @@ # [completion] -# types -if False: +TYPE_CHECKING = False +if TYPE_CHECKING: from .historical_reader import HistoricalReader diff --git a/Lib/_pyrepl/completing_reader.py b/Lib/_pyrepl/completing_reader.py index 1cd4b6367ca8b1..c5b748b1b9869a 100644 --- a/Lib/_pyrepl/completing_reader.py +++ b/Lib/_pyrepl/completing_reader.py @@ -27,11 +27,12 @@ from .reader import Reader -# types -Command = commands.Command -if False: +TYPE_CHECKING = False +if TYPE_CHECKING: from .types import KeySpec, CommandName +Command = commands.Command + def prefix(wordlist: list[str], j: int = 0) -> str: d = {} diff --git a/Lib/_pyrepl/historical_reader.py b/Lib/_pyrepl/historical_reader.py index c4b95fa2e81ee6..8474fe0bef85dc 100644 --- a/Lib/_pyrepl/historical_reader.py +++ b/Lib/_pyrepl/historical_reader.py @@ -26,7 +26,8 @@ from .reader import Reader -if False: +TYPE_CHECKING = False +if TYPE_CHECKING: from .types import SimpleContextManager, KeySpec, CommandName diff --git a/Lib/_pyrepl/input.py b/Lib/_pyrepl/input.py index 21c24eb5cde3e3..0081937f1e1181 100644 --- a/Lib/_pyrepl/input.py +++ b/Lib/_pyrepl/input.py @@ -40,8 +40,8 @@ from collections import deque -# types -if False: +TYPE_CHECKING = False +if TYPE_CHECKING: from .types import EventTuple diff --git a/Lib/_pyrepl/pager.py b/Lib/_pyrepl/pager.py index 1fddc63e3ee3ad..e0c4a0d66bdc37 100644 --- a/Lib/_pyrepl/pager.py +++ b/Lib/_pyrepl/pager.py @@ -6,8 +6,8 @@ import sys -# types -if False: +TYPE_CHECKING = False +if TYPE_CHECKING: from typing import Protocol class Pager(Protocol): def __call__(self, text: str, title: str = "") -> None: diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py index a065174ad42fb6..6beb2c45aeedb8 100644 --- a/Lib/_pyrepl/simple_interact.py +++ b/Lib/_pyrepl/simple_interact.py @@ -30,14 +30,12 @@ import functools import os import sys -import code -from .readline import _get_reader, multiline_input +from .readline import _get_reader, multiline_input, _setup TYPE_CHECKING = False - if TYPE_CHECKING: - from typing import Any + from code import InteractiveConsole _error: tuple[type[Exception], ...] | type[Exception] @@ -83,7 +81,7 @@ def _clear_screen(): } -def _more_lines(console: code.InteractiveConsole, unicodetext: str) -> bool: +def _more_lines(console: InteractiveConsole, unicodetext: str) -> bool: # ooh, look at the hack: src = _strip_final_indent(unicodetext) try: @@ -103,11 +101,10 @@ def _more_lines(console: code.InteractiveConsole, unicodetext: str) -> bool: def run_multiline_interactive_console( - console: code.InteractiveConsole, + console: InteractiveConsole, *, future_flags: int = 0, ) -> None: - from .readline import _setup _setup(console.locals) if future_flags: console.compile.compiler.flags |= future_flags diff --git a/Lib/_pyrepl/trace.py b/Lib/_pyrepl/trace.py index a8eb2433cd3cce..86d5aa41c8db3d 100644 --- a/Lib/_pyrepl/trace.py +++ b/Lib/_pyrepl/trace.py @@ -2,8 +2,8 @@ import os -# types -if False: +TYPE_CHECKING = False +if TYPE_CHECKING: from typing import IO diff --git a/Lib/_pyrepl/unix_console.py b/Lib/_pyrepl/unix_console.py index 96379bc20f3357..2171e58fa192ee 100644 --- a/Lib/_pyrepl/unix_console.py +++ b/Lib/_pyrepl/unix_console.py @@ -41,8 +41,6 @@ TYPE_CHECKING = False - -# types if TYPE_CHECKING: from typing import IO, Literal, overload else: diff --git a/Lib/_pyrepl/windows_console.py b/Lib/_pyrepl/windows_console.py index e1ecd9845aefb4..6322b872663037 100644 --- a/Lib/_pyrepl/windows_console.py +++ b/Lib/_pyrepl/windows_console.py @@ -26,7 +26,6 @@ import msvcrt from collections import deque -import ctypes from ctypes.wintypes import ( _COORD, WORD, @@ -531,7 +530,7 @@ class Char(Union): ] -class KeyEvent(ctypes.Structure): +class KeyEvent(Structure): _fields_ = [ ("bKeyDown", BOOL), ("wRepeatCount", WORD), @@ -542,11 +541,11 @@ class KeyEvent(ctypes.Structure): ] -class WindowsBufferSizeEvent(ctypes.Structure): +class WindowsBufferSizeEvent(Structure): _fields_ = [("dwSize", _COORD)] -class ConsoleEvent(ctypes.Union): +class ConsoleEvent(Union): _fields_ = [ ("KeyEvent", KeyEvent), ("WindowsBufferSizeEvent", WindowsBufferSizeEvent), @@ -580,7 +579,7 @@ class INPUT_RECORD(Structure): GetConsoleScreenBufferInfo = _KERNEL32.GetConsoleScreenBufferInfo GetConsoleScreenBufferInfo.argtypes = [ HANDLE, - ctypes.POINTER(CONSOLE_SCREEN_BUFFER_INFO), + POINTER(CONSOLE_SCREEN_BUFFER_INFO), ] GetConsoleScreenBufferInfo.restype = BOOL