From 405b1bdb2fdeba614891173a782cf32c4bb94d03 Mon Sep 17 00:00:00 2001 From: Stephen Morton Date: Sat, 16 Nov 2024 15:16:34 -0800 Subject: [PATCH] `curses._ncurses_version` updates (#13023) Co-authored-by: Alex Waygood --- stdlib/_curses.pyi | 8 ++------ stdlib/curses/__init__.pyi | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/stdlib/_curses.pyi b/stdlib/_curses.pyi index 80075d77e..9e06a1414 100644 --- a/stdlib/_curses.pyi +++ b/stdlib/_curses.pyi @@ -1,6 +1,7 @@ import sys from _typeshed import ReadOnlyBuffer, SupportsRead -from typing import IO, Any, NamedTuple, final, overload +from curses import _ncurses_version +from typing import IO, Any, final, overload from typing_extensions import TypeAlias # NOTE: This module is ordinarily only available on Unix, but the windows-curses @@ -549,9 +550,4 @@ class window: # undocumented @overload def vline(self, y: int, x: int, ch: _ChType, n: int) -> None: ... -class _ncurses_version(NamedTuple): - major: int - minor: int - patch: int - ncurses_version: _ncurses_version diff --git a/stdlib/curses/__init__.pyi b/stdlib/curses/__init__.pyi index 939cec0ce..edc64a00c 100644 --- a/stdlib/curses/__init__.pyi +++ b/stdlib/curses/__init__.pyi @@ -1,7 +1,9 @@ +import sys from _curses import * from _curses import window as window +from _typeshed import structseq from collections.abc import Callable -from typing import TypeVar +from typing import Final, TypeVar, final, type_check_only from typing_extensions import Concatenate, ParamSpec # NOTE: The _curses module is ordinarily only available on Unix, but the @@ -25,3 +27,19 @@ def wrapper(func: Callable[Concatenate[window, _P], _T], /, *arg: _P.args, **kwd # it was mapped to the name 'window' in 3.8. # Kept here as a legacy alias in case any third-party code is relying on it. _CursesWindow = window + +# At runtime this class is unexposed and calls itself curses.ncurses_version. +# That name would conflict with the actual curses.ncurses_version, which is +# an instance of this class. +@final +@type_check_only +class _ncurses_version(structseq[int], tuple[int, int, int]): + if sys.version_info >= (3, 10): + __match_args__: Final = ("major", "minor", "patch") + + @property + def major(self) -> int: ... + @property + def minor(self) -> int: ... + @property + def patch(self) -> int: ...