[3.13] Improve `pyrepl` type-annotation coverage (GH-119081) by miss-islington · Pull Request #119415 · python/cpython · GitHub
Skip to content
Merged
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
2 changes: 1 addition & 1 deletion Lib/_pyrepl/_minimal_curses.py
4 changes: 2 additions & 2 deletions Lib/_pyrepl/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def empty(self) -> bool:


class KeymapTranslator(InputTranslator):
def __init__(self, keymap, verbose=0, invalid_cls=None, character_cls=None):
def __init__(self, keymap, verbose=False, invalid_cls=None, character_cls=None):
self.verbose = verbose
from .keymap import compile_keymap, parse_keys

Expand Down Expand Up @@ -110,5 +110,5 @@ def get(self):
else:
return None

def empty(self):
def empty(self) -> bool:
return not self.results
2 changes: 1 addition & 1 deletion Lib/_pyrepl/keymap.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def _parse_key1(key, s):
return ret, s


def parse_keys(key):
def parse_keys(key: str) -> list[str]:
s = 0
r = []
while s < len(key):
Expand Down
8 changes: 6 additions & 2 deletions Lib/_pyrepl/pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,14 @@ def tty_pager(text: str, title: str = '') -> None:
fd = sys.stdin.fileno()
old = termios.tcgetattr(fd)
tty.setcbreak(fd)
getchar = lambda: sys.stdin.read(1)
has_tty = True

def getchar() -> str:
return sys.stdin.read(1)

except (ImportError, AttributeError, io.UnsupportedOperation):
getchar = lambda: sys.stdin.readline()[:-1][:1]
def getchar() -> str:
return sys.stdin.readline()[:-1][:1]

try:
try:
Expand Down
7 changes: 5 additions & 2 deletions Lib/_pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@
from .types import Callback, Completer, KeySpec, CommandName


MoreLinesCallable = Callable[[str], bool]


__all__ = [
"add_history",
"clear_history",
Expand Down Expand Up @@ -95,7 +98,7 @@ class ReadlineAlikeReader(historical_reader.HistoricalReader, CompletingReader):

# Instance fields
config: ReadlineConfig
more_lines: Callable[[str], bool] | None = None
more_lines: MoreLinesCallable | None = None

def __post_init__(self) -> None:
super().__post_init__()
Expand Down Expand Up @@ -288,7 +291,7 @@ def input(self, prompt: object = "") -> str:
reader.ps1 = str(prompt)
return reader.readline(startup_hook=self.startup_hook)

def multiline_input(self, more_lines, ps1, ps2):
def multiline_input(self, more_lines: MoreLinesCallable, ps1: str, ps2: str) -> tuple[str, bool]:
"""Read an input on possibly multiple lines, asking for more
lines as long as 'more_lines(unicodetext)' returns an object whose
boolean value is true.
Expand Down
22 changes: 16 additions & 6 deletions Lib/_pyrepl/unix_console.py