Skip to content

gh-129758: Correct imports in Lib/_pyrepl #129761

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
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
4 changes: 2 additions & 2 deletions Lib/_pyrepl/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
# [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 @@ -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 = {}
Expand Down
3 changes: 2 additions & 1 deletion Lib/_pyrepl/historical_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
from .reader import Reader


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


Expand Down
4 changes: 2 additions & 2 deletions Lib/_pyrepl/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
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 @@ -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:
Expand Down
11 changes: 4 additions & 7 deletions Lib/_pyrepl/simple_interact.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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:
Expand All @@ -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
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
4 changes: 2 additions & 2 deletions Lib/_pyrepl/trace.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

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 @@ -41,8 +41,6 @@


TYPE_CHECKING = False

# types
if TYPE_CHECKING:
from typing import IO, Literal, overload
else:
Expand Down
9 changes: 4 additions & 5 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 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