diff --git a/Lib/_pyrepl/_module_completer.py b/Lib/_pyrepl/_module_completer.py index 17bf5cdc819542..280a666e0c78f3 100644 --- a/Lib/_pyrepl/_module_completer.py +++ b/Lib/_pyrepl/_module_completer.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import importlib import os import pkgutil @@ -15,12 +13,9 @@ from tokenize import TokenInfo from .fancycompleter import safe_getattr -TYPE_CHECKING = False - -if TYPE_CHECKING: - from types import ModuleType - from typing import Any, Iterable, Iterator, Mapping - from .types import CompletionAction +lazy from types import ModuleType +lazy from typing import Any, Iterable, Iterator, Mapping +lazy from .types import CompletionAction HARDCODED_SUBMODULES = { diff --git a/Lib/_pyrepl/commands.py b/Lib/_pyrepl/commands.py index e79fbfa6bb0b38..cf8b1a6c1e4ec4 100644 --- a/Lib/_pyrepl/commands.py +++ b/Lib/_pyrepl/commands.py @@ -19,10 +19,8 @@ # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -from __future__ import annotations import os import time -from typing import TYPE_CHECKING # Categories of actions: # killing @@ -37,8 +35,7 @@ from .trace import trace # types -if TYPE_CHECKING: - from .historical_reader import HistoricalReader +lazy from .historical_reader import HistoricalReader class Command: diff --git a/Lib/_pyrepl/completing_reader.py b/Lib/_pyrepl/completing_reader.py index f783e8db36b028..4505c5fe9d7a20 100644 --- a/Lib/_pyrepl/completing_reader.py +++ b/Lib/_pyrepl/completing_reader.py @@ -21,7 +21,6 @@ from __future__ import annotations from dataclasses import dataclass, field -from typing import TYPE_CHECKING import re from . import commands, console, reader @@ -30,9 +29,7 @@ # types -Command = commands.Command -if TYPE_CHECKING: - from .types import CommandName, CompletionAction, Keymap, KeySpec +lazy from .types import CompletionAction, Keymap def prefix(wordlist: list[str], j: int = 0) -> str: @@ -285,7 +282,7 @@ def collect_keymap(self) -> Keymap: return super().collect_keymap() + ( (r'\t', 'complete'),) - def after_command(self, cmd: Command) -> None: + def after_command(self, cmd: commands.Command) -> None: super().after_command(cmd) if not isinstance(cmd, (complete, self_insert)): self.cmpltn_reset() diff --git a/Lib/_pyrepl/console.py b/Lib/_pyrepl/console.py index 2a53d5ff581fa2..dcf8ff9b083caa 100644 --- a/Lib/_pyrepl/console.py +++ b/Lib/_pyrepl/console.py @@ -17,8 +17,6 @@ # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -from __future__ import annotations - import os import _colorize @@ -29,15 +27,13 @@ from dataclasses import dataclass import re import sys -from typing import TYPE_CHECKING from .render import RenderedScreen from .trace import trace -if TYPE_CHECKING: - from typing import Callable, IO - - from .types import CursorXY +lazy from collections.abc import Callable +lazy from typing import IO +lazy from .types import CursorXY @dataclass diff --git a/Lib/_pyrepl/content.py b/Lib/_pyrepl/content.py index 3cb22fee84b740..2e759072662ba4 100644 --- a/Lib/_pyrepl/content.py +++ b/Lib/_pyrepl/content.py @@ -1,5 +1,3 @@ -from __future__ import annotations - from dataclasses import dataclass from .utils import ColorSpan, StyleRef, THEME, iter_display_chars, unbracket, wlen diff --git a/Lib/_pyrepl/fancy_termios.py b/Lib/_pyrepl/fancy_termios.py index 8d5bd183f21339..076a38ad06da17 100644 --- a/Lib/_pyrepl/fancy_termios.py +++ b/Lib/_pyrepl/fancy_termios.py @@ -19,13 +19,7 @@ import termios - -TYPE_CHECKING = False - -if TYPE_CHECKING: - from typing import cast -else: - cast = lambda typ, val: val +from typing import cast class TermState: diff --git a/Lib/_pyrepl/fancycompleter.py b/Lib/_pyrepl/fancycompleter.py index ac4f0afdbc721c..15bbede92cab8d 100644 --- a/Lib/_pyrepl/fancycompleter.py +++ b/Lib/_pyrepl/fancycompleter.py @@ -3,27 +3,23 @@ # # All Rights Reserved """Colorful tab completion for Python prompt""" -from __future__ import annotations - from _colorize import ANSIColors, get_colors, get_theme import rlcompleter import keyword import types -TYPE_CHECKING = False - -if TYPE_CHECKING: - from typing import Any - from _colorize import Theme +lazy from typing import Any +lazy from _colorize import Theme -def safe_getattr(obj, name): +def safe_getattr(obj: object, name: str) -> object: # Mirror rlcompleter's safeguards so completion does not # call properties or reify lazy module attributes. if isinstance(getattr(type(obj), name, None), property): return None if (isinstance(obj, types.ModuleType) - and isinstance(obj.__dict__.get(name), types.LazyImportType) + # TODO: Should be resolved once mypy upgrades typeshed + and isinstance(obj.__dict__.get(name), types.LazyImportType) # type: ignore[attr-defined] ): return obj.__dict__.get(name) return getattr(obj, name, None) @@ -35,7 +31,7 @@ def colorize_matches(names: list[str], values: list[Any], theme: Theme) -> list[ for name, obj in zip(names, values) ] -def _color_for_obj(name: str, value: Any, theme: Theme) -> str: +def _color_for_obj(name: str, value: object, theme: Theme) -> str: t = type(value) color = _color_by_type(t, theme) return f"{color}{name}{ANSIColors.RESET}" diff --git a/Lib/_pyrepl/historical_reader.py b/Lib/_pyrepl/historical_reader.py index 09b969d80bc231..b2192061dcab99 100644 --- a/Lib/_pyrepl/historical_reader.py +++ b/Lib/_pyrepl/historical_reader.py @@ -17,17 +17,13 @@ # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -from __future__ import annotations - from contextlib import contextmanager from dataclasses import dataclass, field from . import commands, input from .reader import Reader - -if False: - from .types import SimpleContextManager, KeySpec, CommandName +lazy from .types import SimpleContextManager, KeySpec, CommandName isearch_keymap: tuple[tuple[KeySpec, CommandName], ...] = tuple( diff --git a/Lib/_pyrepl/input.py b/Lib/_pyrepl/input.py index 2d65246c700f27..56781662b4fda2 100644 --- a/Lib/_pyrepl/input.py +++ b/Lib/_pyrepl/input.py @@ -33,17 +33,12 @@ # [meta-key] is identified with [esc key]. We demand that any console # class does quite a lot towards emulating a unix terminal. -from __future__ import annotations - from abc import ABC, abstractmethod import unicodedata from collections import deque -from typing import TYPE_CHECKING - # types -if TYPE_CHECKING: - from .types import EventTuple +lazy from .types import EventTuple class InputTranslator(ABC): diff --git a/Lib/_pyrepl/layout.py b/Lib/_pyrepl/layout.py index 6d854d1142dd9f..cff0821cb95f72 100644 --- a/Lib/_pyrepl/layout.py +++ b/Lib/_pyrepl/layout.py @@ -1,12 +1,11 @@ """Wrap content lines to the terminal width before rendering.""" -from __future__ import annotations - from dataclasses import dataclass from typing import Self from .content import ContentFragment, ContentLine -from .types import CursorXY, ScreenInfoRow + +lazy from .types import CursorXY, ScreenInfoRow @dataclass(frozen=True, slots=True) diff --git a/Lib/_pyrepl/mypy.ini b/Lib/_pyrepl/mypy.ini index 9375a55b53ce8b..2510ee8c2d3f5a 100644 --- a/Lib/_pyrepl/mypy.ini +++ b/Lib/_pyrepl/mypy.ini @@ -6,7 +6,7 @@ files = Lib/_pyrepl mypy_path = $MYPY_CONFIG_FILE_DIR/../../Misc/mypy explicit_package_bases = True -python_version = 3.13 +python_version = 3.15 platform = linux pretty = True diff --git a/Lib/_pyrepl/pager.py b/Lib/_pyrepl/pager.py index 92afaa5933a225..d6f20fe7557e6b 100644 --- a/Lib/_pyrepl/pager.py +++ b/Lib/_pyrepl/pager.py @@ -1,5 +1,3 @@ -from __future__ import annotations - import io import os import re diff --git a/Lib/_pyrepl/reader.py b/Lib/_pyrepl/reader.py index 7e4dd801c84d5c..b5686409c37cdb 100644 --- a/Lib/_pyrepl/reader.py +++ b/Lib/_pyrepl/reader.py @@ -19,8 +19,6 @@ # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -from __future__ import annotations - import sys import _colorize @@ -38,7 +36,7 @@ ) from .layout import LayoutMap, LayoutResult, LayoutRow, WrappedRow, layout_content_lines from .render import RenderCell, RenderLine, RenderedScreen, ScreenOverlay -from .utils import ANSI_ESCAPE_SEQUENCE, ColorSpan, THEME, StyleRef, wlen, gen_colors +from .utils import ANSI_ESCAPE_SEQUENCE, ColorSpan, THEME, StyleRef, gen_colors from .trace import trace diff --git a/Lib/_pyrepl/readline.py b/Lib/_pyrepl/readline.py index e4370b0d1462ea..1d00de3683db23 100644 --- a/Lib/_pyrepl/readline.py +++ b/Lib/_pyrepl/readline.py @@ -26,8 +26,6 @@ extensions for multiline input. """ -from __future__ import annotations - import warnings from dataclasses import dataclass, field @@ -55,13 +53,10 @@ # types Command = commands.Command -from collections.abc import Callable, Collection +from collections.abc import Callable, Collection, Mapping from .types import Callback, Completer, KeySpec, CommandName, CompletionAction -TYPE_CHECKING = False - -if TYPE_CHECKING: - from typing import Any, Mapping +lazy from typing import Any MoreLinesCallable = Callable[[str], bool] diff --git a/Lib/_pyrepl/simple_interact.py b/Lib/_pyrepl/simple_interact.py index c169d0191bd833..09c7de3712b6d4 100644 --- a/Lib/_pyrepl/simple_interact.py +++ b/Lib/_pyrepl/simple_interact.py @@ -23,8 +23,6 @@ allowing multiline input and multiline history entries. """ -from __future__ import annotations - import _sitebuiltins import functools import os diff --git a/Lib/_pyrepl/trace.py b/Lib/_pyrepl/trace.py index 395867805196a5..1c24ab479fcb63 100644 --- a/Lib/_pyrepl/trace.py +++ b/Lib/_pyrepl/trace.py @@ -1,11 +1,7 @@ -from __future__ import annotations - import os import sys -# types -if False: - from typing import IO +lazy from typing import IO trace_file: IO[str] | None = None diff --git a/Lib/_pyrepl/unix_console.py b/Lib/_pyrepl/unix_console.py index 9c4644db53e343..f28078b8b29738 100644 --- a/Lib/_pyrepl/unix_console.py +++ b/Lib/_pyrepl/unix_console.py @@ -19,8 +19,6 @@ # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -from __future__ import annotations - import errno import os import re @@ -34,7 +32,7 @@ from collections.abc import Callable from dataclasses import dataclass from fcntl import ioctl -from typing import TYPE_CHECKING, cast, overload +from typing import AbstractSet, IO, Literal, overload from . import terminfo from .console import Console, Event @@ -59,9 +57,6 @@ posix = None # types -if TYPE_CHECKING: - from typing import AbstractSet, IO, Literal - type _MoveFunc = Callable[[int, int], None] type _PendingWrite = tuple[str | bytes, bool] diff --git a/Lib/_pyrepl/utils.py b/Lib/_pyrepl/utils.py index b50426c31ead53..7c2c699c8de231 100644 --- a/Lib/_pyrepl/utils.py +++ b/Lib/_pyrepl/utils.py @@ -1,4 +1,3 @@ -from __future__ import annotations import builtins import functools import keyword @@ -9,10 +8,12 @@ import _colorize from collections import deque +from collections.abc import Iterable, Iterator from dataclasses import dataclass from io import StringIO +from re import Match from tokenize import TokenInfo as TI -from typing import Iterable, Iterator, Match, NamedTuple, Self +from typing import NamedTuple, Self from .types import CharBuffer, CharWidths from .trace import trace diff --git a/Lib/_pyrepl/windows_console.py b/Lib/_pyrepl/windows_console.py index c1f9a19545d35f..40bc47d6597a42 100644 --- a/Lib/_pyrepl/windows_console.py +++ b/Lib/_pyrepl/windows_console.py @@ -17,8 +17,6 @@ # CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN # CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -from __future__ import annotations - import io import os import sys @@ -38,7 +36,6 @@ SHORT, ) from ctypes import Structure, POINTER, Union -from typing import TYPE_CHECKING from .console import Event, Console from .render import ( EMPTY_RENDER_LINE, @@ -73,8 +70,7 @@ def __init__(self, err: int | None, descr: str | None = None) -> None: except ImportError: nt = None -if TYPE_CHECKING: - from typing import IO +lazy from typing import IO # Virtual-Key Codes: https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes VK_MAP: dict[int, str] = {