Skip to content

Commit 13a74a5

Browse files
authored
Update tkinter.Text.count() for Python 3.13 (Akuli's version) (#12629)
1 parent 6cddd30 commit 13a74a5

File tree

2 files changed

+148
-21
lines changed

2 files changed

+148
-21
lines changed

stdlib/@tests/test_cases/check_tkinter.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__ import annotations
22

3+
import sys
34
import tkinter
45
import traceback
56
import types
@@ -52,3 +53,23 @@ def foo(x: int, y: str) -> None:
5253
assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "update"), Tuple[int, ...]) # (0, 0, 0)
5354
assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "ypixels"), Tuple[int, ...]) # (15, 1, 15, 19)
5455
assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "ypixels"), Tuple[int, ...]) # (0, 0, 0, 0)
56+
57+
if sys.version_info >= (3, 13):
58+
assert_type(t.count("1.0", "2.3", return_ints=True), int) # 15
59+
assert_type(t.count("2.3", "2.3", return_ints=True), int) # 0
60+
assert_type(t.count("1.0", "2.3", "indices", return_ints=True), int) # 15
61+
assert_type(t.count("2.3", "2.3", "indices", return_ints=True), int) # 0
62+
assert_type(t.count("1.0", "2.3", "indices", "update", return_ints=True), int) # 15
63+
assert_type(t.count("2.3", "2.3", "indices", "update", return_ints=True), int) # 0
64+
assert_type(t.count("1.0", "2.3", "indices", "lines", return_ints=True), Tuple[int, int]) # (15, 1)
65+
assert_type(t.count("2.3", "2.3", "indices", "lines", return_ints=True), Tuple[int, int]) # (0, 0)
66+
assert_type(t.count("1.0", "2.3", "indices", "lines", "update", return_ints=True), Tuple[int, ...]) # (15, 1)
67+
assert_type(t.count("2.3", "2.3", "indices", "lines", "update", return_ints=True), Tuple[int, ...]) # (0, 0)
68+
assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", return_ints=True), Tuple[int, ...]) # (15, 1, 15)
69+
assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", return_ints=True), Tuple[int, ...]) # (0, 0, 0)
70+
assert_type(t.count("1.0", "2.3", "indices", "lines", "chars", "update", return_ints=True), Tuple[int, ...]) # (15, 1, 15)
71+
assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "update", return_ints=True), Tuple[int, ...]) # (0, 0, 0)
72+
assert_type(
73+
t.count("1.0", "2.3", "indices", "lines", "chars", "ypixels", return_ints=True), Tuple[int, ...]
74+
) # (15, 1, 15, 19)
75+
assert_type(t.count("2.3", "2.3", "indices", "lines", "chars", "ypixels", return_ints=True), Tuple[int, ...]) # (0, 0, 0, 0)

stdlib/tkinter/__init__.pyi

Lines changed: 127 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3025,27 +3025,133 @@ class Text(Widget, XView, YView):
30253025
config = configure
30263026
def bbox(self, index: _TextIndex) -> tuple[int, int, int, int] | None: ... # type: ignore[override]
30273027
def compare(self, index1: _TextIndex, op: Literal["<", "<=", "==", ">=", ">", "!="], index2: _TextIndex) -> bool: ...
3028-
@overload
3029-
def count(self, index1: _TextIndex, index2: _TextIndex) -> tuple[int] | None: ...
3030-
@overload
3031-
def count(self, index1: _TextIndex, index2: _TextIndex, arg: _WhatToCount | Literal["update"], /) -> tuple[int] | None: ...
3032-
@overload
3033-
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: Literal["update"], arg2: _WhatToCount, /) -> int | None: ...
3034-
@overload
3035-
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: Literal["update"], /) -> int | None: ...
3036-
@overload
3037-
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: _WhatToCount, /) -> tuple[int, int]: ...
3038-
@overload
3039-
def count(
3040-
self,
3041-
index1: _TextIndex,
3042-
index2: _TextIndex,
3043-
arg1: _WhatToCount | Literal["update"],
3044-
arg2: _WhatToCount | Literal["update"],
3045-
arg3: _WhatToCount | Literal["update"],
3046-
/,
3047-
*args: _WhatToCount | Literal["update"],
3048-
) -> tuple[int, ...]: ...
3028+
if sys.version_info >= (3, 13):
3029+
@overload
3030+
def count(self, index1: _TextIndex, index2: _TextIndex, *, return_ints: Literal[True]) -> int: ...
3031+
@overload
3032+
def count(
3033+
self, index1: _TextIndex, index2: _TextIndex, arg: _WhatToCount | Literal["update"], /, *, return_ints: Literal[True]
3034+
) -> int: ...
3035+
@overload
3036+
def count(
3037+
self,
3038+
index1: _TextIndex,
3039+
index2: _TextIndex,
3040+
arg1: Literal["update"],
3041+
arg2: _WhatToCount,
3042+
/,
3043+
*,
3044+
return_ints: Literal[True],
3045+
) -> int: ...
3046+
@overload
3047+
def count(
3048+
self,
3049+
index1: _TextIndex,
3050+
index2: _TextIndex,
3051+
arg1: _WhatToCount,
3052+
arg2: Literal["update"],
3053+
/,
3054+
*,
3055+
return_ints: Literal[True],
3056+
) -> int: ...
3057+
@overload
3058+
def count(
3059+
self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: _WhatToCount, /, *, return_ints: Literal[True]
3060+
) -> tuple[int, int]: ...
3061+
@overload
3062+
def count(
3063+
self,
3064+
index1: _TextIndex,
3065+
index2: _TextIndex,
3066+
arg1: _WhatToCount | Literal["update"],
3067+
arg2: _WhatToCount | Literal["update"],
3068+
arg3: _WhatToCount | Literal["update"],
3069+
/,
3070+
*args: _WhatToCount | Literal["update"],
3071+
return_ints: Literal[True],
3072+
) -> tuple[int, ...]: ...
3073+
@overload
3074+
def count(self, index1: _TextIndex, index2: _TextIndex, *, return_ints: Literal[False] = False) -> tuple[int] | None: ...
3075+
@overload
3076+
def count(
3077+
self,
3078+
index1: _TextIndex,
3079+
index2: _TextIndex,
3080+
arg: _WhatToCount | Literal["update"],
3081+
/,
3082+
*,
3083+
return_ints: Literal[False] = False,
3084+
) -> tuple[int] | None: ...
3085+
@overload
3086+
def count(
3087+
self,
3088+
index1: _TextIndex,
3089+
index2: _TextIndex,
3090+
arg1: Literal["update"],
3091+
arg2: _WhatToCount,
3092+
/,
3093+
*,
3094+
return_ints: Literal[False] = False,
3095+
) -> int | None: ...
3096+
@overload
3097+
def count(
3098+
self,
3099+
index1: _TextIndex,
3100+
index2: _TextIndex,
3101+
arg1: _WhatToCount,
3102+
arg2: Literal["update"],
3103+
/,
3104+
*,
3105+
return_ints: Literal[False] = False,
3106+
) -> int | None: ...
3107+
@overload
3108+
def count(
3109+
self,
3110+
index1: _TextIndex,
3111+
index2: _TextIndex,
3112+
arg1: _WhatToCount,
3113+
arg2: _WhatToCount,
3114+
/,
3115+
*,
3116+
return_ints: Literal[False] = False,
3117+
) -> tuple[int, int]: ...
3118+
@overload
3119+
def count(
3120+
self,
3121+
index1: _TextIndex,
3122+
index2: _TextIndex,
3123+
arg1: _WhatToCount | Literal["update"],
3124+
arg2: _WhatToCount | Literal["update"],
3125+
arg3: _WhatToCount | Literal["update"],
3126+
/,
3127+
*args: _WhatToCount | Literal["update"],
3128+
return_ints: Literal[False] = False,
3129+
) -> tuple[int, ...]: ...
3130+
else:
3131+
@overload
3132+
def count(self, index1: _TextIndex, index2: _TextIndex) -> tuple[int] | None: ...
3133+
@overload
3134+
def count(
3135+
self, index1: _TextIndex, index2: _TextIndex, arg: _WhatToCount | Literal["update"], /
3136+
) -> tuple[int] | None: ...
3137+
@overload
3138+
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: Literal["update"], arg2: _WhatToCount, /) -> int | None: ...
3139+
@overload
3140+
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: Literal["update"], /) -> int | None: ...
3141+
@overload
3142+
def count(self, index1: _TextIndex, index2: _TextIndex, arg1: _WhatToCount, arg2: _WhatToCount, /) -> tuple[int, int]: ...
3143+
@overload
3144+
def count(
3145+
self,
3146+
index1: _TextIndex,
3147+
index2: _TextIndex,
3148+
arg1: _WhatToCount | Literal["update"],
3149+
arg2: _WhatToCount | Literal["update"],
3150+
arg3: _WhatToCount | Literal["update"],
3151+
/,
3152+
*args: _WhatToCount | Literal["update"],
3153+
) -> tuple[int, ...]: ...
3154+
30493155
@overload
30503156
def debug(self, boolean: None = None) -> bool: ...
30513157
@overload

0 commit comments

Comments
 (0)