Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 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
2 changes: 1 addition & 1 deletion Lib/_pyrepl/_threading_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from dataclasses import dataclass, field
import traceback


TYPE_CHECKING = False

if TYPE_CHECKING:
from threading import Thread
from types import TracebackType
Expand Down
5 changes: 3 additions & 2 deletions Lib/_pyrepl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
# [completion]


# types
if False:
TYPE_CHECKING = False

if TYPE_CHECKING:
from .historical_reader import HistoricalReader


Expand Down
7 changes: 4 additions & 3 deletions Lib/_pyrepl/completing_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@
from . import commands, console, reader
from .reader import Reader

TYPE_CHECKING = False

# types
Command = commands.Command
if False:
if TYPE_CHECKING:
from .types import KeySpec, CommandName

Command = commands.Command


def prefix(wordlist: list[str], j: int = 0) -> str:
d = {}
Expand Down
4 changes: 3 additions & 1 deletion Lib/_pyrepl/historical_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
from .reader import Reader


if False:
TYPE_CHECKING = False

if TYPE_CHECKING:
from .types import SimpleContextManager, KeySpec, CommandName


Expand Down
5 changes: 3 additions & 2 deletions Lib/_pyrepl/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@
from collections import deque


# types
if False:
TYPE_CHECKING = False

if TYPE_CHECKING:
from .types import EventTuple


Expand Down
4 changes: 2 additions & 2 deletions Lib/_pyrepl/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
import re
import sys

TYPE_CHECKING = False

# types
if False:
if TYPE_CHECKING:
from typing import Protocol
class Pager(Protocol):
def __call__(self, text: str, title: str = "") -> None:
Expand Down
1 change: 0 additions & 1 deletion Lib/_pyrepl/reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
from .utils import ANSI_ESCAPE_SEQUENCE, wlen, str_width
from .trace import trace


# types
Command = commands.Command
from .types import Callback, SimpleContextManager, KeySpec, CommandName
Expand Down
3 changes: 2 additions & 1 deletion Lib/_pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

from __future__ import annotations

import warnings
from dataclasses import dataclass, field

import os
Expand Down Expand Up @@ -377,6 +376,8 @@ def multiline_input(self, more_lines: MoreLinesCallable, ps1: str, ps2: str) ->
lines as long as 'more_lines(unicodetext)' returns an object whose
boolean value is true.
"""
import warnings

reader = self.get_reader()
saved = reader.more_lines
try:
Expand Down
12 changes: 5 additions & 7 deletions Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,21 @@
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]
try:
from .unix_console import _error
except ModuleNotFoundError:
from .windows_console import _error


def check() -> str:
"""Returns the error message if there is a problem initializing the state."""
try:
Expand Down Expand Up @@ -83,7 +82,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:
Expand All @@ -103,11 +102,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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, don't change this line.

Copy link
Contributor Author

@donBarbos donBarbos Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sobolevn ok, but why? We already have import _setup on 34 line

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, the default position is the status quo, you need to justify every change.

Copy link
Contributor Author

@donBarbos donBarbos Feb 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed it because it duplicates imports. As I already said it is on line 34

_setup(console.locals)
if future_flags:
console.compile.compiler.flags |= future_flags
Expand Down
5 changes: 3 additions & 2 deletions Lib/_pyrepl/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

import os

# types
if False:
TYPE_CHECKING = False

if TYPE_CHECKING:
from typing import IO


Expand Down
2 changes: 0 additions & 2 deletions Lib/_pyrepl/unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,8 @@
from .unix_eventqueue import EventQueue
from .utils import wlen


TYPE_CHECKING = False

# types
if TYPE_CHECKING:
from typing import IO, Literal, overload
else:
Expand Down
11 changes: 5 additions & 6 deletions Lib/_pyrepl/windows_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import msvcrt

from collections import deque
import ctypes
from ctypes.wintypes import (
_COORD,
WORD,
Expand All @@ -45,7 +44,7 @@

try:
from ctypes import GetLastError, WinDLL, windll, WinError # type: ignore[attr-defined]
except:
except ImportError:
# Keep MyPy happy off Windows
from ctypes import CDLL as WinDLL, cdll as windll

Expand Down Expand Up @@ -531,7 +530,7 @@ class Char(Union):
]


class KeyEvent(ctypes.Structure):
class KeyEvent(Structure):
_fields_ = [
("bKeyDown", BOOL),
("wRepeatCount", WORD),
Expand All @@ -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),
Expand Down Expand Up @@ -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

Expand Down
Loading