From 13a74a521106fe3eac5acd31d51bfb6a85d9ed3c Mon Sep 17 00:00:00 2001 From: Akuli Date: Wed, 25 Sep 2024 09:08:11 +0300 Subject: [PATCH] Update `tkinter.Text.count()` for Python 3.13 (Akuli's version) (#12629) --- stdlib/@tests/test_cases/check_tkinter.py | 21 +++ stdlib/tkinter/__init__.pyi | 148 +++++++++++++++++++--- 2 files changed, 148 insertions(+), 21 deletions(-) diff --git a/stdlib/@tests/test_cases/check_tkinter.py b/stdlib/@tests/test_cases/check_tkinter.py index ffee64dcb..eb344f3a2 100644 --- a/stdlib/@tests/test_cases/check_tkinter.py +++ b/stdlib/@tests/test_cases/check_tkinter.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys import tkinter import traceback import types @@ -52,3 +53,23 @@ assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "update"), Tuple[ assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "update"), Tuple[int, ...]) # (0, 0, 0) assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "ypixels"), Tuple[int, ...]) # (15, 1, 15, 19) assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "ypixels"), Tuple[int, ...]) # (0, 0, 0, 0) + +if sys.version_info >= (3, 13): + assert_type(t.count("1.0", "2.3", return_ints=True), int) # 15 + assert_type(t.count("2.3", "2.3", return_ints=True), int) # 0 + assert_type(t.count("1.0", "2.3", "indices", return_ints=True), int) # 15 + assert_type(t.count("2.3", "2.3", "indices", return_ints=True), int) # 0 + assert_type(t.count("1.0", "2.3", "indices", "update", return_ints=True), int) # 15 + assert_type(t.count("2.3", "2.3", "indices", "update", return_ints=True), int) # 0 + assert_type(t.count("1.0", "2.3", "indices", "lines", return_ints=True), Tuple[int, int]) # (15, 1) + assert_type(t.count("2.3", "2.3", "indices", "lines", return_ints=True), Tuple[int, int]) # (0, 0) + assert_type(t.count("1.0", "2.3", "indices", "lines", "update", return_ints=True), Tuple[int, ...]) # (15, 1) + assert_type(t.count("2.3", "2.3", "indices", "lines", "update", return_ints=True), Tuple[int, ...]) # (0, 0) + assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", return_ints=True), Tuple[int, ...]) # (15, 1, 15) + assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", return_ints=True), Tuple[int, ...]) # (0, 0, 0) + assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "update", return_ints=True), Tuple[int, ...]) # (15, 1, 15) + assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "update", return_ints=True), Tuple[int, ...]) # (0, 0, 0) + assert_type( + t.count("1.0", "2.3", "indices", "lines", "chars", "ypixels", return_ints=True), Tuple[int, ...] + ) # (15, 1, 15, 19) + assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "ypixels", return_ints=True), Tuple[int, ...]) # (0, 0, 0, 0) diff --git a/stdlib/tkinter/__init__.pyi b/stdlib/tkinter/__init__.pyi index 2a42eb789..4d25a04f8 100644 --- a/stdlib/tkinter/__init__.pyi +++ b/stdlib/tkinter/__init__.pyi @@ -3025,27 +3025,133 @@ class Text(Widget, XView, YView): config = configure def bbox(self, index: _TextIndex) -> tuple[int, int, int, int] | None: ... # type: ignore[override] def compare(self, index1: _TextIndex, op: Literal["<", "<=", "==", ">=", ">", "!="], index2: _TextIndex) -> bool: ... - @overload - def count(self, index1: _TextIndex, index2: _TextIndex) -> tuple[int] | None: ... - @overload - def count(self, index1: _TextIndex, index2: _TextIndex, arg: _WhatToCount | Literal["update"], /) -> tuple[int] | None: ... - @overload - def count(self, index1: _TextIndex, index2: _TextIndex, arg1: Literal["update"], arg2: _WhatToCount, /) -> int | None: ... - @overload - def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: Literal["update"], /) -> int | None: ... - @overload - def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: _WhatToCount, /) -> tuple[int, int]: ... - @overload - def count( - self, - index1: _TextIndex, - index2: _TextIndex, - arg1: _WhatToCount | Literal["update"], - arg2: _WhatToCount | Literal["update"], - arg3: _WhatToCount | Literal["update"], - /, - *args: _WhatToCount | Literal["update"], - ) -> tuple[int, ...]: ... + if sys.version_info >= (3, 13): + @overload + def count(self, index1: _TextIndex, index2: _TextIndex, *, return_ints: Literal[True]) -> int: ... + @overload + def count( + self, index1: _TextIndex, index2: _TextIndex, arg: _WhatToCount | Literal["update"], /, *, return_ints: Literal[True] + ) -> int: ... + @overload + def count( + self, + index1: _TextIndex, + index2: _TextIndex, + arg1: Literal["update"], + arg2: _WhatToCount, + /, + *, + return_ints: Literal[True], + ) -> int: ... + @overload + def count( + self, + index1: _TextIndex, + index2: _TextIndex, + arg1: _WhatToCount, + arg2: Literal["update"], + /, + *, + return_ints: Literal[True], + ) -> int: ... + @overload + def count( + self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: _WhatToCount, /, *, return_ints: Literal[True] + ) -> tuple[int, int]: ... + @overload + def count( + self, + index1: _TextIndex, + index2: _TextIndex, + arg1: _WhatToCount | Literal["update"], + arg2: _WhatToCount | Literal["update"], + arg3: _WhatToCount | Literal["update"], + /, + *args: _WhatToCount | Literal["update"], + return_ints: Literal[True], + ) -> tuple[int, ...]: ... + @overload + def count(self, index1: _TextIndex, index2: _TextIndex, *, return_ints: Literal[False] = False) -> tuple[int] | None: ... + @overload + def count( + self, + index1: _TextIndex, + index2: _TextIndex, + arg: _WhatToCount | Literal["update"], + /, + *, + return_ints: Literal[False] = False, + ) -> tuple[int] | None: ... + @overload + def count( + self, + index1: _TextIndex, + index2: _TextIndex, + arg1: Literal["update"], + arg2: _WhatToCount, + /, + *, + return_ints: Literal[False] = False, + ) -> int | None: ... + @overload + def count( + self, + index1: _TextIndex, + index2: _TextIndex, + arg1: _WhatToCount, + arg2: Literal["update"], + /, + *, + return_ints: Literal[False] = False, + ) -> int | None: ... + @overload + def count( + self, + index1: _TextIndex, + index2: _TextIndex, + arg1: _WhatToCount, + arg2: _WhatToCount, + /, + *, + return_ints: Literal[False] = False, + ) -> tuple[int, int]: ... + @overload + def count( + self, + index1: _TextIndex, + index2: _TextIndex, + arg1: _WhatToCount | Literal["update"], + arg2: _WhatToCount | Literal["update"], + arg3: _WhatToCount | Literal["update"], + /, + *args: _WhatToCount | Literal["update"], + return_ints: Literal[False] = False, + ) -> tuple[int, ...]: ... + else: + @overload + def count(self, index1: _TextIndex, index2: _TextIndex) -> tuple[int] | None: ... + @overload + def count( + self, index1: _TextIndex, index2: _TextIndex, arg: _WhatToCount | Literal["update"], / + ) -> tuple[int] | None: ... + @overload + def count(self, index1: _TextIndex, index2: _TextIndex, arg1: Literal["update"], arg2: _WhatToCount, /) -> int | None: ... + @overload + def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: Literal["update"], /) -> int | None: ... + @overload + def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: _WhatToCount, /) -> tuple[int, int]: ... + @overload + def count( + self, + index1: _TextIndex, + index2: _TextIndex, + arg1: _WhatToCount | Literal["update"], + arg2: _WhatToCount | Literal["update"], + arg3: _WhatToCount | Literal["update"], + /, + *args: _WhatToCount | Literal["update"], + ) -> tuple[int, ...]: ... + @overload def debug(self, boolean: None = None) -> bool: ... @overload