Skip to content

Commit 1c6349e

Browse files
authored
Merge branch 'main' into fpdf2-2.8.5
2 parents 51af77e + a3568ac commit 1c6349e

File tree

78 files changed

+1386
-264
lines changed

Some content is hidden

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

78 files changed

+1386
-264
lines changed

CONTRIBUTING.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -344,20 +344,20 @@ the latest mypy (`pip install -r requirements-tests.txt`) before running the scr
344344

345345
### Supported type system features
346346

347-
Since PEP 484 was accepted, there have been many other PEPs that added
348-
new features to the Python type system. In general, new features can
349-
be used in typeshed as soon as the PEP has been accepted and implemented
350-
and most type checkers support the new feature.
347+
Since [PEP 484](https://peps.python.org/pep-0484/) was accepted, there have been
348+
many other PEPs that added new features to the Python type system. In general,
349+
new features can be used in typeshed as soon as the PEP has been accepted and
350+
implemented and most type checkers support the new feature.
351351

352352
Supported features include:
353-
- [PEP 544](https://peps.python.org/pep-0544/) (Protocol)
353+
- [PEP 544](https://peps.python.org/pep-0544/) (`Protocol`)
354354
- [PEP 585](https://peps.python.org/pep-0585/) (builtin generics)
355-
- [PEP 586](https://peps.python.org/pep-0586/) (Literal)
356-
- [PEP 591](https://peps.python.org/pep-0591/) (Final/@final)
357-
- [PEP 589](https://peps.python.org/pep-0589/) (TypedDict)
355+
- [PEP 586](https://peps.python.org/pep-0586/) (`Literal`)
356+
- [PEP 591](https://peps.python.org/pep-0591/) (`Final`/`@final`)
357+
- [PEP 589](https://peps.python.org/pep-0589/) (`TypedDict`)
358358
- [PEP 604](https://peps.python.org/pep-0604/) (`Foo | Bar` union syntax)
359-
- [PEP 612](https://peps.python.org/pep-0612/) (ParamSpec)
360-
- [PEP 647](https://peps.python.org/pep-0647/) (TypeGuard):
359+
- [PEP 612](https://peps.python.org/pep-0612/) (`ParamSpec`)
360+
- [PEP 647](https://peps.python.org/pep-0647/) (`TypeGuard`):
361361
see [#5406](https://github.com/python/typeshed/issues/5406)
362362
- [PEP 655](https://peps.python.org/pep-0655/) (`Required` and `NotRequired`)
363363
- [PEP 673](https://peps.python.org/pep-0673/) (`Self`)

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",

stdlib/@tests/stubtest_allowlists/linux.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ fcntl.I_[A-Z0-9_]+ # Platform differences that cannot be captured by the type s
2727
multiprocessing.popen_spawn_win32 # exists on Linux but fails to import
2828
select.poll # Actually a function; we have a class so it can be used as a type
2929

30+
# Bluetooth constants which aren't on the GitHub Actions runners, see #15207
31+
(_?socket\.AF_BLUETOOTH)?
32+
(_?socket\.BDADDR_ANY)?
33+
(_?socket\.BDADDR_LOCAL)?
34+
(_?socket\.BTPROTO_HCI)?
35+
(_?socket\.BTPROTO_L2CAP)?
36+
(_?socket\.BTPROTO_RFCOMM)?
37+
(_?socket\.BTPROTO_SCO)?
38+
3039
# These seem like they should be available on Linux, but they're not
3140
# on GitHub Actions runners for some reason.
3241
_?socket.IPX_TYPE
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from typing_extensions import Literal, assert_type
2+
3+
4+
# Note: type checkers / linters are free to point out that the set difference
5+
# below is redundant. But typeshed should allow it, as its job is to describe
6+
# what is legal in Python, not what is sensible.
7+
# For instance, set[Literal] - set[str] should be legal.
8+
def test_set_difference(x: set[Literal["foo", "bar"]], y: set[str], z: set[int]) -> None:
9+
assert_type(x - y, set[Literal["foo", "bar"]])
10+
assert_type(y - x, set[str])
11+
assert_type(x - z, set[Literal["foo", "bar"]])
12+
assert_type(z - x, set[int])
13+
assert_type(y - z, set[str])
14+
assert_type(z - y, set[int])
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/_socket.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ if sys.platform != "linux":
587587

588588
has_ipv6: bool
589589

590-
if sys.platform != "darwin" and sys.platform != "linux":
590+
if sys.platform != "darwin":
591591
BDADDR_ANY: Final = "00:00:00:00:00:00"
592592
BDADDR_LOCAL: Final = "00:00:00:FF:FF:FF"
593593

@@ -660,16 +660,16 @@ if sys.platform == "darwin":
660660
PF_SYSTEM: Final[int]
661661
SYSPROTO_CONTROL: Final[int]
662662

663-
if sys.platform != "darwin" and sys.platform != "linux":
663+
if sys.platform != "darwin":
664664
AF_BLUETOOTH: Final[int]
665665

666-
if sys.platform != "win32" and sys.platform != "darwin" and sys.platform != "linux":
666+
if sys.platform != "win32" and sys.platform != "darwin":
667667
# Linux and some BSD support is explicit in the docs
668668
# Windows and macOS do not support in practice
669669
BTPROTO_HCI: Final[int]
670670
BTPROTO_L2CAP: Final[int]
671671
BTPROTO_SCO: Final[int] # not in FreeBSD
672-
if sys.platform != "darwin" and sys.platform != "linux":
672+
if sys.platform != "darwin":
673673
BTPROTO_RFCOMM: Final[int]
674674

675675
if sys.platform == "linux":

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,7 +1282,7 @@ class set(MutableSet[_T]):
12821282
def __iand__(self, value: AbstractSet[object], /) -> Self: ...
12831283
def __or__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
12841284
def __ior__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
1285-
def __sub__(self, value: AbstractSet[_T | None], /) -> set[_T]: ...
1285+
def __sub__(self, value: AbstractSet[object], /) -> set[_T]: ...
12861286
def __isub__(self, value: AbstractSet[object], /) -> Self: ...
12871287
def __xor__(self, value: AbstractSet[_S], /) -> set[_T | _S]: ...
12881288
def __ixor__(self, value: AbstractSet[_T], /) -> Self: ... # type: ignore[override,misc]
@@ -1313,7 +1313,7 @@ class frozenset(AbstractSet[_T_co]):
13131313
def __iter__(self) -> Iterator[_T_co]: ...
13141314
def __and__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ...
13151315
def __or__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
1316-
def __sub__(self, value: AbstractSet[_T_co], /) -> frozenset[_T_co]: ...
1316+
def __sub__(self, value: AbstractSet[object], /) -> frozenset[_T_co]: ...
13171317
def __xor__(self, value: AbstractSet[_S], /) -> frozenset[_T_co | _S]: ...
13181318
def __le__(self, value: AbstractSet[object], /) -> bool: ...
13191319
def __lt__(self, value: AbstractSet[object], /) -> bool: ...

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: ...

0 commit comments

Comments
 (0)