Skip to content

Commit 8531886

Browse files
Merge branch 'main' into set_sub
2 parents f7af3f7 + bcf2ccf commit 8531886

File tree

95 files changed

+1657
-406
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1657
-406
lines changed

lib/ts_utils/utils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@ def strip_comments(text: str) -> str:
3535
return text.split("#")[0].strip()
3636

3737

38+
def json5_to_json(text: str) -> str:
39+
"""Incomplete conversion from JSON5-like input to valid JSON."""
40+
# Remove full-line // comments only
41+
# (Can not remove inline comments)
42+
text = re.sub(r"(?m)^\s*//.*\n?", "", text)
43+
# Remove trailing commas before } or ]
44+
text = re.sub(r",\s*([}\]])", r"\1", text)
45+
return text
46+
47+
3848
# ====================================================================
3949
# Printing utilities
4050
# ====================================================================

pyrightconfig.stricter.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,16 @@
99
// test cases use a custom pyrightconfig file
1010
"**/@tests/test_cases",
1111
"stdlib/__main__.pyi",
12+
"stdlib/_tkinter.pyi",
1213
"stdlib/distutils/cmd.pyi",
1314
"stdlib/distutils/command",
1415
"stdlib/distutils/dist.pyi",
1516
"stdlib/encodings/__init__.pyi",
1617
"stdlib/lib2to3/fixes/*.pyi",
1718
"stdlib/numbers.pyi",
18-
"stdlib/_tkinter.pyi",
1919
"stdlib/tkinter/__init__.pyi",
20-
"stdlib/tkinter/filedialog.pyi",
2120
"stdlib/tkinter/dialog.pyi",
21+
"stdlib/tkinter/filedialog.pyi",
2222
"stdlib/tkinter/scrolledtext.pyi",
2323
"stdlib/tkinter/tix.pyi",
2424
"stdlib/tkinter/ttk.pyi",
@@ -74,6 +74,7 @@
7474
"stubs/protobuf",
7575
"stubs/psutil/psutil/__init__.pyi",
7676
"stubs/psycopg2",
77+
"stubs/punq",
7778
"stubs/pyasn1",
7879
"stubs/pycurl",
7980
"stubs/Pygments",
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from __future__ import annotations
2+
3+
import sys
4+
from typing_extensions import assert_type
5+
6+
if sys.version_info >= (3, 13):
7+
from itertools import batched
8+
9+
assert_type(batched([0], 1, strict=True), batched[tuple[int]])
10+
assert_type(batched([0, 0], 2, strict=True), batched[tuple[int, int]])
11+
assert_type(batched([0, 0, 0], 3, strict=True), batched[tuple[int, int, int]])
12+
assert_type(batched([0, 0, 0, 0], 4, strict=True), batched[tuple[int, int, int, int]])
13+
assert_type(batched([0, 0, 0, 0, 0], 5, strict=True), batched[tuple[int, int, int, int, int]])
14+
15+
assert_type(batched([0], 2), batched[tuple[int, ...]])
16+
assert_type(batched([0], 2, strict=False), batched[tuple[int, ...]])
17+
18+
def f() -> int:
19+
return 3
20+
21+
assert_type(batched([0, 0, 0], f(), strict=True), batched[tuple[int, ...]])

stdlib/_tkinter.pyi

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
2+
from _typeshed import FileDescriptorLike, Incomplete
23
from collections.abc import Callable
3-
from typing import Any, ClassVar, Final, final
4+
from typing import Any, ClassVar, Final, Literal, final, overload
45
from typing_extensions import TypeAlias, deprecated
56

67
# _tkinter is meant to be only used internally by tkinter, but some tkinter
@@ -54,22 +55,23 @@ _TkinterTraceFunc: TypeAlias = Callable[[tuple[str, ...]], object]
5455
@final
5556
class TkappType:
5657
# Please keep in sync with tkinter.Tk
57-
def adderrorinfo(self, msg: str, /): ...
58+
def adderrorinfo(self, msg: str, /) -> None: ...
5859
def call(self, command: Any, /, *args: Any) -> Any: ...
59-
def createcommand(self, name: str, func, /): ...
60+
# TODO: Figure out what arguments the following `func` callbacks should accept
61+
def createcommand(self, name: str, func: Callable[..., object], /) -> None: ...
6062
if sys.platform != "win32":
61-
def createfilehandler(self, file, mask: int, func, /): ...
62-
def deletefilehandler(self, file, /) -> None: ...
63+
def createfilehandler(self, file: FileDescriptorLike, mask: int, func: Callable[..., object], /) -> None: ...
64+
def deletefilehandler(self, file: FileDescriptorLike, /) -> None: ...
6365

64-
def createtimerhandler(self, milliseconds: int, func, /): ...
65-
def deletecommand(self, name: str, /): ...
66-
def dooneevent(self, flags: int = 0, /): ...
66+
def createtimerhandler(self, milliseconds: int, func: Callable[..., object], /): ...
67+
def deletecommand(self, name: str, /) -> None: ...
68+
def dooneevent(self, flags: int = 0, /) -> int: ...
6769
def eval(self, script: str, /) -> str: ...
68-
def evalfile(self, fileName: str, /): ...
69-
def exprboolean(self, s: str, /): ...
70-
def exprdouble(self, s: str, /): ...
71-
def exprlong(self, s: str, /): ...
72-
def exprstring(self, s: str, /): ...
70+
def evalfile(self, fileName: str, /) -> str: ...
71+
def exprboolean(self, s: str, /) -> Literal[0, 1]: ...
72+
def exprdouble(self, s: str, /) -> float: ...
73+
def exprlong(self, s: str, /) -> int: ...
74+
def exprstring(self, s: str, /) -> str: ...
7375
def getboolean(self, arg, /) -> bool: ...
7476
def getdouble(self, arg, /) -> float: ...
7577
def getint(self, arg, /) -> int: ...
@@ -81,15 +83,23 @@ class TkappType:
8183
def loadtk(self) -> None: ...
8284
def mainloop(self, threshold: int = 0, /) -> None: ...
8385
def quit(self) -> None: ...
84-
def record(self, script: str, /): ...
86+
def record(self, script: str, /) -> str: ...
8587
def setvar(self, *ags, **kwargs): ...
8688
if sys.version_info < (3, 11):
8789
@deprecated("Deprecated since Python 3.9; removed in Python 3.11. Use `splitlist()` instead.")
8890
def split(self, arg, /): ...
8991

90-
def splitlist(self, arg, /): ...
92+
def splitlist(self, arg, /) -> tuple[Incomplete, ...]: ...
9193
def unsetvar(self, *args, **kwargs): ...
92-
def wantobjects(self, *args, **kwargs): ...
94+
if sys.version_info >= (3, 14):
95+
@overload
96+
def wantobjects(self) -> Literal[0, 1]: ...
97+
else:
98+
@overload
99+
def wantobjects(self) -> bool: ...
100+
101+
@overload
102+
def wantobjects(self, wantobjects: Literal[0, 1] | bool, /) -> None: ...
93103
def willdispatch(self) -> None: ...
94104
if sys.version_info >= (3, 12):
95105
def gettrace(self, /) -> _TkinterTraceFunc | None: ...
@@ -112,7 +122,7 @@ TK_VERSION: Final[str]
112122

113123
@final
114124
class TkttType:
115-
def deletetimerhandler(self): ...
125+
def deletetimerhandler(self) -> None: ...
116126

117127
if sys.version_info >= (3, 13):
118128
def create(
@@ -125,7 +135,7 @@ if sys.version_info >= (3, 13):
125135
sync: bool = False,
126136
use: str | None = None,
127137
/,
128-
): ...
138+
) -> TkappType: ...
129139

130140
else:
131141
def create(
@@ -138,7 +148,7 @@ else:
138148
sync: bool = False,
139149
use: str | None = None,
140150
/,
141-
): ...
151+
) -> TkappType: ...
142152

143153
def getbusywaitinterval() -> int: ...
144154
def setbusywaitinterval(new_val: int, /) -> None: ...

stdlib/builtins.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,9 +1176,9 @@ class dict(MutableMapping[_KT, _VT]):
11761176
# __init__ should be kept roughly in line with `collections.UserDict.__init__`, which has similar semantics
11771177
# Also multiprocessing.managers.SyncManager.dict()
11781178
@overload
1179-
def __init__(self) -> None: ...
1179+
def __init__(self, /) -> None: ...
11801180
@overload
1181-
def __init__(self: dict[str, _VT], **kwargs: _VT) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780
1181+
def __init__(self: dict[str, _VT], /, **kwargs: _VT) -> None: ... # pyright: ignore[reportInvalidTypeVarUse] #11780
11821182
@overload
11831183
def __init__(self, map: SupportsKeysAndGetItem[_KT, _VT], /) -> None: ...
11841184
@overload
@@ -1203,7 +1203,7 @@ class dict(MutableMapping[_KT, _VT]):
12031203
def __init__(self: dict[str, str], iterable: Iterable[list[str]], /) -> None: ...
12041204
@overload
12051205
def __init__(self: dict[bytes, bytes], iterable: Iterable[list[bytes]], /) -> None: ...
1206-
def __new__(cls, *args: Any, **kwargs: Any) -> Self: ...
1206+
def __new__(cls, /, *args: Any, **kwargs: Any) -> Self: ...
12071207
def copy(self) -> dict[_KT, _VT]: ...
12081208
def keys(self) -> dict_keys[_KT, _VT]: ...
12091209
def values(self) -> dict_values[_KT, _VT]: ...

stdlib/cmath.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ nan: Final[float]
99
nanj: Final[complex]
1010
tau: Final[float]
1111

12+
_F: TypeAlias = SupportsFloat | SupportsIndex
1213
_C: TypeAlias = SupportsFloat | SupportsComplex | SupportsIndex | complex
1314

1415
def acos(z: _C, /) -> complex: ...
@@ -27,7 +28,7 @@ def log(z: _C, base: _C = ..., /) -> complex: ...
2728
def log10(z: _C, /) -> complex: ...
2829
def phase(z: _C, /) -> float: ...
2930
def polar(z: _C, /) -> tuple[float, float]: ...
30-
def rect(r: float, phi: float, /) -> complex: ...
31+
def rect(r: _F, phi: _F, /) -> complex: ...
3132
def sin(z: _C, /) -> complex: ...
3233
def sinh(z: _C, /) -> complex: ...
3334
def sqrt(z: _C, /) -> complex: ...

stdlib/ctypes/__init__.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,12 @@ def create_unicode_buffer(init: int | str, size: int | None = None) -> Array[c_w
169169
if sys.version_info >= (3, 13):
170170
@deprecated("Deprecated since Python 3.13; will be removed in Python 3.15.")
171171
def SetPointerType(pointer: type[_Pointer[Any]], cls: _CTypeBaseType) -> None: ...
172+
@deprecated("Soft deprecated since Python 3.13. Use multiplication instead.")
173+
def ARRAY(typ: _CT, len: int) -> Array[_CT]: ...
172174

173175
else:
174176
def SetPointerType(pointer: type[_Pointer[Any]], cls: _CTypeBaseType) -> None: ...
175-
176-
def ARRAY(typ: _CT, len: int) -> Array[_CT]: ... # Soft Deprecated, no plans to remove
177+
def ARRAY(typ: _CT, len: int) -> Array[_CT]: ...
177178

178179
if sys.platform == "win32":
179180
def DllCanUnloadNow() -> int: ...

stdlib/email/utils.pyi

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,7 @@ def parsedate(data: str) -> tuple[int, int, int, int, int, int, int, int, int] |
4444
def parsedate_tz(data: None) -> None: ...
4545
@overload
4646
def parsedate_tz(data: str) -> _PDTZ | None: ...
47-
48-
if sys.version_info >= (3, 10):
49-
@overload
50-
def parsedate_to_datetime(data: None) -> None: ...
51-
@overload
52-
def parsedate_to_datetime(data: str) -> datetime.datetime: ...
53-
54-
else:
55-
def parsedate_to_datetime(data: str) -> datetime.datetime: ...
56-
47+
def parsedate_to_datetime(data: str) -> datetime.datetime: ...
5748
def mktime_tz(data: _PDTZ) -> int: ...
5849
def formatdate(timeval: float | None = None, localtime: bool = False, usegmt: bool = False) -> str: ...
5950
def format_datetime(dt: datetime.datetime, usegmt: bool = False) -> str: ...

stdlib/faulthandler.pyi

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ from _typeshed import FileDescriptorLike
33

44
def cancel_dump_traceback_later() -> None: ...
55
def disable() -> None: ...
6-
def dump_traceback(file: FileDescriptorLike = ..., all_threads: bool = ...) -> None: ...
6+
def dump_traceback(file: FileDescriptorLike = sys.stderr, all_threads: bool = True) -> None: ...
77

88
if sys.version_info >= (3, 14):
9-
def dump_c_stack(file: FileDescriptorLike = ...) -> None: ...
9+
def dump_c_stack(file: FileDescriptorLike = sys.stderr) -> None: ...
1010

11-
def dump_traceback_later(timeout: float, repeat: bool = ..., file: FileDescriptorLike = ..., exit: bool = ...) -> None: ...
11+
def dump_traceback_later(
12+
timeout: float, repeat: bool = False, file: FileDescriptorLike = sys.stderr, exit: bool = False
13+
) -> None: ...
1214

1315
if sys.version_info >= (3, 14):
14-
def enable(file: FileDescriptorLike = ..., all_threads: bool = ..., c_stack: bool = True) -> None: ...
16+
def enable(file: FileDescriptorLike = sys.stderr, all_threads: bool = True, c_stack: bool = True) -> None: ...
1517

1618
else:
17-
def enable(file: FileDescriptorLike = ..., all_threads: bool = ...) -> None: ...
19+
def enable(file: FileDescriptorLike = sys.stderr, all_threads: bool = True) -> None: ...
1820

1921
def is_enabled() -> bool: ...
2022

2123
if sys.platform != "win32":
22-
def register(signum: int, file: FileDescriptorLike = ..., all_threads: bool = ..., chain: bool = ...) -> None: ...
24+
def register(signum: int, file: FileDescriptorLike = sys.stderr, all_threads: bool = True, chain: bool = False) -> None: ...
2325
def unregister(signum: int, /) -> None: ...

stdlib/ftplib.pyi

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import sys
2-
from _typeshed import SupportsRead, SupportsReadline
2+
from _typeshed import StrOrBytesPath, SupportsRead, SupportsReadline
33
from collections.abc import Callable, Iterable, Iterator
44
from socket import socket
55
from ssl import SSLContext
66
from types import TracebackType
7-
from typing import Any, Final, Literal, TextIO
8-
from typing_extensions import Self
7+
from typing import Any, Final, Literal, TextIO, overload
8+
from typing_extensions import Self, deprecated
99

1010
__all__ = ["FTP", "error_reply", "error_temp", "error_perm", "error_proto", "all_errors", "FTP_TLS"]
1111

@@ -120,23 +120,43 @@ class FTP_TLS(FTP):
120120
encoding: str = "utf-8",
121121
) -> None: ...
122122
else:
123+
@overload
123124
def __init__(
124125
self,
125126
host: str = "",
126127
user: str = "",
127128
passwd: str = "",
128129
acct: str = "",
129-
keyfile: str | None = None,
130-
certfile: str | None = None,
130+
keyfile: None = None,
131+
certfile: None = None,
131132
context: SSLContext | None = None,
132133
timeout: float | None = ...,
133134
source_address: tuple[str, int] | None = None,
134135
*,
135136
encoding: str = "utf-8",
136137
) -> None: ...
137-
ssl_version: int
138-
keyfile: str | None
139-
certfile: str | None
138+
@overload
139+
@deprecated(
140+
"The `keyfile`, `certfile` parameters are deprecated since Python 3.6; "
141+
"removed in Python 3.12. Use `context` parameter instead."
142+
)
143+
def __init__(
144+
self,
145+
host: str = "",
146+
user: str = "",
147+
passwd: str = "",
148+
acct: str = "",
149+
keyfile: StrOrBytesPath | None = None,
150+
certfile: StrOrBytesPath | None = None,
151+
context: None = None,
152+
timeout: float | None = ...,
153+
source_address: tuple[str, int] | None = None,
154+
*,
155+
encoding: str = "utf-8",
156+
) -> None: ...
157+
ssl_version: int
158+
keyfile: StrOrBytesPath | None
159+
certfile: StrOrBytesPath | None
140160
context: SSLContext
141161
def login(self, user: str = "", passwd: str = "", acct: str = "", secure: bool = True) -> str: ...
142162
def auth(self) -> str: ...

0 commit comments

Comments
 (0)