From 0aa98c6f285835d3adce2d6679cf37fc85b97755 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 17 Dec 2021 08:00:20 -0800 Subject: [PATCH 1/6] Fixes to curses stubs Fixes python/mypy#11768. I reviewed all the function definitions in https://github.com/python/cpython/blob/3.9/Modules/_cursesmodule.c#L4152 and checked their types. I did not review the constants or the methods on the Window object. --- stdlib/_curses.pyi | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 80e7776c1f0a..51ad56c4fe53 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -293,9 +293,12 @@ 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 +340,9 @@ 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 +350,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 +368,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: ... From 7d465538065eace9674d5ef0ba533b0371b4ba72 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 17 Dec 2021 08:00:52 -0800 Subject: [PATCH 2/6] add import --- stdlib/_curses.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 51ad56c4fe53..9f9d77e8e332 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,5 +1,6 @@ import sys from typing import IO, Any, BinaryIO, NamedTuple, Union, overload +from _typeshed import SupportsRead _chtype = Union[str, bytes, int] From 84c97a06b7704db0b9fd6cd182dabf3bec12225f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 17 Dec 2021 16:01:31 +0000 Subject: [PATCH 3/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_curses.pyi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 9f9d77e8e332..3bd16dc02c7d 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -294,9 +294,11 @@ 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: SupportsRead[bytes]) -> _CursesWindow: ... @@ -341,9 +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: ... From b3de5a5f6d76bfbb0547d06f0b8450599518085d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 17 Dec 2021 16:02:32 +0000 Subject: [PATCH 4/6] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stdlib/_curses.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 3bd16dc02c7d..3249089fc30d 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,6 +1,6 @@ import sys -from typing import IO, Any, BinaryIO, NamedTuple, Union, overload from _typeshed import SupportsRead +from typing import IO, Any, BinaryIO, NamedTuple, Union, overload _chtype = Union[str, bytes, int] From 52606b842c844e5c150432649a03c33ba1056e96 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 17 Dec 2021 08:12:58 -0800 Subject: [PATCH 5/6] Update stdlib/_curses.pyi --- stdlib/_curses.pyi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 3249089fc30d..d2eb1e1a4efb 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,6 +1,6 @@ import sys from _typeshed import SupportsRead -from typing import IO, Any, BinaryIO, NamedTuple, Union, overload +from typing import IO, Any, NamedTuple, Union, overload _chtype = Union[str, bytes, int] From 30a18a617f0316402e0e54ad59d3cb54ae568cff Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Fri, 17 Dec 2021 09:20:22 -0800 Subject: [PATCH 6/6] clean up allowlists --- tests/stubtest_allowlists/darwin-py310.txt | 4 ---- tests/stubtest_allowlists/darwin-py39.txt | 4 ---- tests/stubtest_allowlists/linux-py310.txt | 4 ---- tests/stubtest_allowlists/linux-py39.txt | 4 ---- 4 files changed, 16 deletions(-) diff --git a/tests/stubtest_allowlists/darwin-py310.txt b/tests/stubtest_allowlists/darwin-py310.txt index 10ce26026ecd..d6256794a9e8 100644 --- a/tests/stubtest_allowlists/darwin-py310.txt +++ b/tests/stubtest_allowlists/darwin-py310.txt @@ -3,10 +3,6 @@ _curses.color_pair curses.color_pair # Exists at runtime, but missing from stubs -_curses.get_escdelay -_curses.get_tabsize -_curses.set_escdelay -_curses.set_tabsize asyncio.PidfdChildWatcher asyncio.unix_events.PidfdChildWatcher os.CLD_KILLED diff --git a/tests/stubtest_allowlists/darwin-py39.txt b/tests/stubtest_allowlists/darwin-py39.txt index 1a75d252c504..6c7075800257 100644 --- a/tests/stubtest_allowlists/darwin-py39.txt +++ b/tests/stubtest_allowlists/darwin-py39.txt @@ -1,10 +1,6 @@ _?curses.A_ITALIC # Exists at runtime, but missing from stubs -_curses.get_escdelay -_curses.get_tabsize -_curses.set_escdelay -_curses.set_tabsize asyncio.PidfdChildWatcher asyncio.unix_events.PidfdChildWatcher os.CLD_KILLED diff --git a/tests/stubtest_allowlists/linux-py310.txt b/tests/stubtest_allowlists/linux-py310.txt index 768560017ce0..aa9d84584ee3 100644 --- a/tests/stubtest_allowlists/linux-py310.txt +++ b/tests/stubtest_allowlists/linux-py310.txt @@ -18,10 +18,6 @@ signal.sigwaitinfo select.epoll.register # Exists at runtime, but missing from stubs -_curses.get_escdelay -_curses.get_tabsize -_curses.set_escdelay -_curses.set_tabsize asyncio.PidfdChildWatcher asyncio.unix_events.PidfdChildWatcher os.CLD_KILLED diff --git a/tests/stubtest_allowlists/linux-py39.txt b/tests/stubtest_allowlists/linux-py39.txt index 046b7923cce6..a88f186c39f0 100644 --- a/tests/stubtest_allowlists/linux-py39.txt +++ b/tests/stubtest_allowlists/linux-py39.txt @@ -2,10 +2,6 @@ select.epoll.register # Exists at runtime, but missing from stubs -_curses.get_escdelay -_curses.get_tabsize -_curses.set_escdelay -_curses.set_tabsize asyncio.PidfdChildWatcher asyncio.unix_events.PidfdChildWatcher os.CLD_KILLED