|
40 | 40 | from .utils import wlen
|
41 | 41 |
|
42 | 42 |
|
| 43 | +TYPE_CHECKING = False |
| 44 | + |
43 | 45 | # types
|
44 |
| -if False: |
45 |
| - from typing import IO |
| 46 | +if TYPE_CHECKING: |
| 47 | + from typing import IO, Literal, overload |
| 48 | +else: |
| 49 | + overload = lambda func: None |
46 | 50 |
|
47 | 51 |
|
48 | 52 | class InvalidTerminal(RuntimeError):
|
@@ -157,7 +161,13 @@ def __init__(
|
157 | 161 | curses.setupterm(term or None, self.output_fd)
|
158 | 162 | self.term = term
|
159 | 163 |
|
160 |
| - def _my_getstr(cap, optional=0): |
| 164 | + @overload |
| 165 | + def _my_getstr(cap: str, optional: Literal[False] = False) -> bytes: ... |
| 166 | + |
| 167 | + @overload |
| 168 | + def _my_getstr(cap: str, optional: bool) -> bytes | None: ... |
| 169 | + |
| 170 | + def _my_getstr(cap: str, optional: bool = False) -> bytes | None: |
161 | 171 | r = curses.tigetstr(cap)
|
162 | 172 | if not optional and r is None:
|
163 | 173 | raise InvalidTerminal(
|
@@ -672,18 +682,18 @@ def __move_y_cuu_cud(self, y):
|
672 | 682 | elif dy < 0:
|
673 | 683 | self.__write_code(self._cuu, -dy)
|
674 | 684 |
|
675 |
| - def __move_x_hpa(self, x): |
| 685 | + def __move_x_hpa(self, x: int) -> None: |
676 | 686 | if x != self.__posxy[0]:
|
677 | 687 | self.__write_code(self._hpa, x)
|
678 | 688 |
|
679 |
| - def __move_x_cub1_cuf1(self, x): |
| 689 | + def __move_x_cub1_cuf1(self, x: int) -> None: |
680 | 690 | dx = x - self.__posxy[0]
|
681 | 691 | if dx > 0:
|
682 | 692 | self.__write_code(self._cuf1 * dx)
|
683 | 693 | elif dx < 0:
|
684 | 694 | self.__write_code(self._cub1 * (-dx))
|
685 | 695 |
|
686 |
| - def __move_x_cub_cuf(self, x): |
| 696 | + def __move_x_cub_cuf(self, x: int) -> None: |
687 | 697 | dx = x - self.__posxy[0]
|
688 | 698 | if dx > 0:
|
689 | 699 | self.__write_code(self._cuf, dx)
|
|
0 commit comments