mirror of
				https://github.com/python/cpython.git
				synced 2025-10-30 21:21:22 +00:00 
			
		
		
		
	[3.13] Improve pyrepl type-annotation coverage (GH-119081) (#119415)
				
					
				
			(cherry picked from commit 033f5c87f1)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
			
			
This commit is contained in:
		
							parent
							
								
									bfd9c3ea53
								
							
						
					
					
						commit
						cd39da75af
					
				
					 6 changed files with 31 additions and 14 deletions
				
			
		|  | @ -17,7 +17,7 @@ class error(Exception): | ||||||
|     pass |     pass | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _find_clib(): | def _find_clib() -> str: | ||||||
|     trylibs = ["ncursesw", "ncurses", "curses"] |     trylibs = ["ncursesw", "ncurses", "curses"] | ||||||
| 
 | 
 | ||||||
|     for lib in trylibs: |     for lib in trylibs: | ||||||
|  |  | ||||||
|  | @ -60,7 +60,7 @@ def empty(self) -> bool: | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class KeymapTranslator(InputTranslator): | 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 |         self.verbose = verbose | ||||||
|         from .keymap import compile_keymap, parse_keys |         from .keymap import compile_keymap, parse_keys | ||||||
| 
 | 
 | ||||||
|  | @ -110,5 +110,5 @@ def get(self): | ||||||
|         else: |         else: | ||||||
|             return None |             return None | ||||||
| 
 | 
 | ||||||
|     def empty(self): |     def empty(self) -> bool: | ||||||
|         return not self.results |         return not self.results | ||||||
|  |  | ||||||
|  | @ -190,7 +190,7 @@ def _parse_key1(key, s): | ||||||
|     return ret, s |     return ret, s | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def parse_keys(key): | def parse_keys(key: str) -> list[str]: | ||||||
|     s = 0 |     s = 0 | ||||||
|     r = [] |     r = [] | ||||||
|     while s < len(key): |     while s < len(key): | ||||||
|  |  | ||||||
|  | @ -76,10 +76,14 @@ def tty_pager(text: str, title: str = '') -> None: | ||||||
|         fd = sys.stdin.fileno() |         fd = sys.stdin.fileno() | ||||||
|         old = termios.tcgetattr(fd) |         old = termios.tcgetattr(fd) | ||||||
|         tty.setcbreak(fd) |         tty.setcbreak(fd) | ||||||
|         getchar = lambda: sys.stdin.read(1) |  | ||||||
|         has_tty = True |         has_tty = True | ||||||
|  | 
 | ||||||
|  |         def getchar() -> str: | ||||||
|  |             return sys.stdin.read(1) | ||||||
|  | 
 | ||||||
|     except (ImportError, AttributeError, io.UnsupportedOperation): |     except (ImportError, AttributeError, io.UnsupportedOperation): | ||||||
|         getchar = lambda: sys.stdin.readline()[:-1][:1] |         def getchar() -> str: | ||||||
|  |             return sys.stdin.readline()[:-1][:1] | ||||||
| 
 | 
 | ||||||
|     try: |     try: | ||||||
|         try: |         try: | ||||||
|  |  | ||||||
|  | @ -49,6 +49,9 @@ | ||||||
| from .types import Callback, Completer, KeySpec, CommandName | from .types import Callback, Completer, KeySpec, CommandName | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | MoreLinesCallable = Callable[[str], bool] | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| __all__ = [ | __all__ = [ | ||||||
|     "add_history", |     "add_history", | ||||||
|     "clear_history", |     "clear_history", | ||||||
|  | @ -95,7 +98,7 @@ class ReadlineAlikeReader(historical_reader.HistoricalReader, CompletingReader): | ||||||
| 
 | 
 | ||||||
|     # Instance fields |     # Instance fields | ||||||
|     config: ReadlineConfig |     config: ReadlineConfig | ||||||
|     more_lines: Callable[[str], bool] | None = None |     more_lines: MoreLinesCallable | None = None | ||||||
| 
 | 
 | ||||||
|     def __post_init__(self) -> None: |     def __post_init__(self) -> None: | ||||||
|         super().__post_init__() |         super().__post_init__() | ||||||
|  | @ -288,7 +291,7 @@ def input(self, prompt: object = "") -> str: | ||||||
|         reader.ps1 = str(prompt) |         reader.ps1 = str(prompt) | ||||||
|         return reader.readline(startup_hook=self.startup_hook) |         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 |         """Read an input on possibly multiple lines, asking for more | ||||||
|         lines as long as 'more_lines(unicodetext)' returns an object whose |         lines as long as 'more_lines(unicodetext)' returns an object whose | ||||||
|         boolean value is true. |         boolean value is true. | ||||||
|  |  | ||||||
|  | @ -40,9 +40,13 @@ | ||||||
| from .utils import wlen | from .utils import wlen | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  | TYPE_CHECKING = False | ||||||
|  | 
 | ||||||
| # types | # types | ||||||
| if False: | if TYPE_CHECKING: | ||||||
|     from typing import IO |     from typing import IO, Literal, overload | ||||||
|  | else: | ||||||
|  |     overload = lambda func: None | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class InvalidTerminal(RuntimeError): | class InvalidTerminal(RuntimeError): | ||||||
|  | @ -157,7 +161,13 @@ def __init__( | ||||||
|         curses.setupterm(term or None, self.output_fd) |         curses.setupterm(term or None, self.output_fd) | ||||||
|         self.term = term |         self.term = term | ||||||
| 
 | 
 | ||||||
|         def _my_getstr(cap, optional=0): |         @overload | ||||||
|  |         def _my_getstr(cap: str, optional: Literal[False] = False) -> bytes: ... | ||||||
|  | 
 | ||||||
|  |         @overload | ||||||
|  |         def _my_getstr(cap: str, optional: bool) -> bytes | None: ... | ||||||
|  | 
 | ||||||
|  |         def _my_getstr(cap: str, optional: bool = False) -> bytes | None: | ||||||
|             r = curses.tigetstr(cap) |             r = curses.tigetstr(cap) | ||||||
|             if not optional and r is None: |             if not optional and r is None: | ||||||
|                 raise InvalidTerminal( |                 raise InvalidTerminal( | ||||||
|  | @ -672,18 +682,18 @@ def __move_y_cuu_cud(self, y): | ||||||
|         elif dy < 0: |         elif dy < 0: | ||||||
|             self.__write_code(self._cuu, -dy) |             self.__write_code(self._cuu, -dy) | ||||||
| 
 | 
 | ||||||
|     def __move_x_hpa(self, x): |     def __move_x_hpa(self, x: int) -> None: | ||||||
|         if x != self.__posxy[0]: |         if x != self.__posxy[0]: | ||||||
|             self.__write_code(self._hpa, x) |             self.__write_code(self._hpa, x) | ||||||
| 
 | 
 | ||||||
|     def __move_x_cub1_cuf1(self, x): |     def __move_x_cub1_cuf1(self, x: int) -> None: | ||||||
|         dx = x - self.__posxy[0] |         dx = x - self.__posxy[0] | ||||||
|         if dx > 0: |         if dx > 0: | ||||||
|             self.__write_code(self._cuf1 * dx) |             self.__write_code(self._cuf1 * dx) | ||||||
|         elif dx < 0: |         elif dx < 0: | ||||||
|             self.__write_code(self._cub1 * (-dx)) |             self.__write_code(self._cub1 * (-dx)) | ||||||
| 
 | 
 | ||||||
|     def __move_x_cub_cuf(self, x): |     def __move_x_cub_cuf(self, x: int) -> None: | ||||||
|         dx = x - self.__posxy[0] |         dx = x - self.__posxy[0] | ||||||
|         if dx > 0: |         if dx > 0: | ||||||
|             self.__write_code(self._cuf, dx) |             self.__write_code(self._cuf, dx) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Miss Islington (bot)
						Miss Islington (bot)