From 750b77df67748e22722158ea5fce3fba083ced25 Mon Sep 17 00:00:00 2001 From: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Date: Mon, 20 Dec 2021 03:07:44 -0800 Subject: [PATCH] [0.930 backport] update curses stubs, cherry pick fix (#11785) Solves #11768 in the 0.930 branch Found by python/typeshed#6620 Co-authored-by: hauntsaninja <> Co-authored-by: Jelle Zijlstra --- mypy/typeshed/stdlib/_curses.pyi | 35 +++++++++++++++++++++----------- mypy/util.py | 5 +++-- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/mypy/typeshed/stdlib/_curses.pyi b/mypy/typeshed/stdlib/_curses.pyi index e0f978c5cae1..d2eb1e1a4efb 100644 --- a/mypy/typeshed/stdlib/_curses.pyi +++ b/mypy/typeshed/stdlib/_curses.pyi @@ -1,5 +1,6 @@ import sys -from typing import IO, Any, BinaryIO, NamedTuple, Union, overload +from _typeshed import SupportsRead +from typing import IO, Any, NamedTuple, Union, overload _chtype = Union[str, bytes, int] @@ -293,9 +294,14 @@ def erasechar() -> bytes: ... def filter() -> None: ... def flash() -> None: ... def flushinp() -> None: ... + +if sys.version_info >= (3, 9): + def get_escdelay() -> int: ... + def get_tabsize() -> int: ... + def getmouse() -> tuple[int, int, int, int, int]: ... def getsyx() -> tuple[int, int]: ... -def getwin(__file: BinaryIO) -> _CursesWindow: ... +def getwin(__file: SupportsRead[bytes]) -> _CursesWindow: ... def halfdelay(__tenths: int) -> None: ... def has_colors() -> bool: ... @@ -337,6 +343,11 @@ def resetty() -> None: ... def resize_term(__nlines: int, __ncols: int) -> None: ... def resizeterm(__nlines: int, __ncols: int) -> None: ... def savetty() -> None: ... + +if sys.version_info >= (3, 9): + def set_escdelay(__ms: int) -> None: ... + def set_tabsize(__size: int) -> None: ... + def setsyx(__y: int, __x: int) -> None: ... def setupterm(term: str | None = ..., fd: int = ...) -> None: ... def start_color() -> None: ... @@ -344,7 +355,7 @@ def termattrs() -> int: ... def termname() -> bytes: ... def tigetflag(__capname: str) -> int: ... def tigetnum(__capname: str) -> int: ... -def tigetstr(__capname: str) -> bytes: ... +def tigetstr(__capname: str) -> bytes | None: ... def tparm( __str: bytes, __i1: int = ..., @@ -362,7 +373,7 @@ def unctrl(__ch: _chtype) -> bytes: ... def unget_wch(__ch: int | str) -> None: ... def ungetch(__ch: _chtype) -> None: ... def ungetmouse(__id: int, __x: int, __y: int, __z: int, __bstate: int) -> None: ... -def update_lines_cols() -> int: ... +def update_lines_cols() -> None: ... def use_default_colors() -> None: ... def use_env(__flag: bool) -> None: ... @@ -444,13 +455,13 @@ class _CursesWindow: def getmaxyx(self) -> tuple[int, int]: ... def getparyx(self) -> tuple[int, int]: ... @overload - def getstr(self) -> _chtype: ... + def getstr(self) -> bytes: ... @overload - def getstr(self, n: int) -> _chtype: ... + def getstr(self, n: int) -> bytes: ... @overload - def getstr(self, y: int, x: int) -> _chtype: ... + def getstr(self, y: int, x: int) -> bytes: ... @overload - def getstr(self, y: int, x: int, n: int) -> _chtype: ... + def getstr(self, y: int, x: int, n: int) -> bytes: ... def getyx(self) -> tuple[int, int]: ... @overload def hline(self, ch: _chtype, n: int) -> None: ... @@ -460,9 +471,9 @@ class _CursesWindow: def idlok(self, yes: bool) -> None: ... def immedok(self, flag: bool) -> None: ... @overload - def inch(self) -> _chtype: ... + def inch(self) -> int: ... @overload - def inch(self, y: int, x: int) -> _chtype: ... + def inch(self, y: int, x: int) -> int: ... @overload def insch(self, ch: _chtype, attr: int = ...) -> None: ... @overload @@ -478,9 +489,9 @@ class _CursesWindow: @overload def insstr(self, y: int, x: int, str: str, attr: int = ...) -> None: ... @overload - def instr(self, n: int = ...) -> _chtype: ... + def instr(self, n: int = ...) -> bytes: ... @overload - def instr(self, y: int, x: int, n: int = ...) -> _chtype: ... + def instr(self, y: int, x: int, n: int = ...) -> bytes: ... def is_linetouched(self, __line: int) -> bool: ... def is_wintouched(self) -> bool: ... def keypad(self, yes: bool) -> None: ... diff --git a/mypy/util.py b/mypy/util.py index b25f069d845d..533e9c6bee6e 100644 --- a/mypy/util.py +++ b/mypy/util.py @@ -566,11 +566,12 @@ def initialize_unix_colors(self) -> bool: under = curses.tigetstr('smul') set_color = curses.tigetstr('setaf') set_eseq = curses.tigetstr('cup') + normal = curses.tigetstr('sgr0') - if not (bold and under and set_color and set_eseq): + if not (bold and under and set_color and set_eseq and normal): return False - self.NORMAL = curses.tigetstr('sgr0').decode() + self.NORMAL = normal.decode() self.BOLD = bold.decode() self.UNDER = under.decode() self.DIM = parse_gray_color(set_eseq)