Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions Lib/_pyrepl/_module_completer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import importlib
import os
import pkgutil
Expand All @@ -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 = {
Expand Down
5 changes: 1 addition & 4 deletions Lib/_pyrepl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
7 changes: 2 additions & 5 deletions Lib/_pyrepl/completing_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
10 changes: 3 additions & 7 deletions Lib/_pyrepl/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions Lib/_pyrepl/content.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

from dataclasses import dataclass

from .utils import ColorSpan, StyleRef, THEME, iter_display_chars, unbracket, wlen
Expand Down
8 changes: 1 addition & 7 deletions Lib/_pyrepl/fancy_termios.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 6 additions & 10 deletions Lib/_pyrepl/fancycompleter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}"
Expand Down
6 changes: 1 addition & 5 deletions Lib/_pyrepl/historical_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 1 addition & 6 deletions Lib/_pyrepl/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
5 changes: 2 additions & 3 deletions Lib/_pyrepl/layout.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion Lib/_pyrepl/mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 0 additions & 2 deletions Lib/_pyrepl/pager.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import annotations

import io
import os
import re
Expand Down
4 changes: 1 addition & 3 deletions Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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


Expand Down
9 changes: 2 additions & 7 deletions Lib/_pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@
extensions for multiline input.
"""

from __future__ import annotations

import warnings
from dataclasses import dataclass, field

Expand Down Expand Up @@ -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]
Expand Down
2 changes: 0 additions & 2 deletions Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
allowing multiline input and multiline history entries.
"""

from __future__ import annotations

import _sitebuiltins
import functools
import os
Expand Down
6 changes: 1 addition & 5 deletions Lib/_pyrepl/trace.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 1 addition & 6 deletions Lib/_pyrepl/unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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]

Expand Down
5 changes: 3 additions & 2 deletions Lib/_pyrepl/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from __future__ import annotations
import builtins
import functools
import keyword
Expand All @@ -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
Expand Down
6 changes: 1 addition & 5 deletions Lib/_pyrepl/windows_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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] = {
Expand Down
Loading