From c6822fe0033f092eeb9e15c4c809d53b5a5e9a76 Mon Sep 17 00:00:00 2001 From: Kirill Klenov Date: Fri, 20 Nov 2026 15:05:38 +0300 Subject: [PATCH 1/5] [peewee] Add stubs for playhouse extension modules MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cover playhouse.sqlite_ext.JSONField, playhouse.postgres_ext.ArrayField and playhouse.test_utils.count_queries, which were missing from the partial stubs. 🖇 --- stubs/peewee/playhouse/postgres_ext.pyi | 18 ++++++++++++++++++ stubs/peewee/playhouse/sqlite_ext.pyi | 11 +++++++++++ stubs/peewee/playhouse/test_utils.pyi | 13 +++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 stubs/peewee/playhouse/postgres_ext.pyi create mode 100644 stubs/peewee/playhouse/sqlite_ext.pyi create mode 100644 stubs/peewee/playhouse/test_utils.pyi diff --git a/stubs/peewee/playhouse/postgres_ext.pyi b/stubs/peewee/playhouse/postgres_ext.pyi new file mode 100644 index 000000000000..ac70de7ce1a3 --- /dev/null +++ b/stubs/peewee/playhouse/postgres_ext.pyi @@ -0,0 +1,18 @@ +from typing import Any + +from peewee import Expression, Field + +class ArrayField(Field[list[Any]]): + dimensions: int + def __init__( + self, + field_class: type[Field[Any]] = ..., + field_kwargs: dict[str, Any] | None = ..., + dimensions: int = 1, + convert_values: bool = False, + *args: Any, + **kwargs: Any, + ) -> None: ... + def contains(self, *items: Any) -> Expression: ... + def contains_any(self, *items: Any) -> Expression: ... + def contained_by(self, *items: Any) -> Expression: ... diff --git a/stubs/peewee/playhouse/sqlite_ext.pyi b/stubs/peewee/playhouse/sqlite_ext.pyi new file mode 100644 index 000000000000..cba4e68db7f7 --- /dev/null +++ b/stubs/peewee/playhouse/sqlite_ext.pyi @@ -0,0 +1,11 @@ +from typing import Any + +from peewee import Expression, TextField + +class JSONField(TextField[str]): + def __init__(self, json_dumps: Any = ..., json_loads: Any = ..., **kwargs: Any) -> None: ... + def db_value(self, value: Any) -> str | None: ... + def python_value(self, value: str | None) -> Any: ... + def children(self) -> Expression: ... + def length(self, path: str | None = None) -> Expression: ... + def json_type(self) -> Expression: ... diff --git a/stubs/peewee/playhouse/test_utils.pyi b/stubs/peewee/playhouse/test_utils.pyi new file mode 100644 index 000000000000..a389837a13be --- /dev/null +++ b/stubs/peewee/playhouse/test_utils.pyi @@ -0,0 +1,13 @@ +from logging import LogRecord +from types import TracebackType + +from typing_extensions import Self + +class count_queries: + count: int + def __init__(self, only_select: bool = False) -> None: ... + def get_queries(self) -> list[LogRecord]: ... + def __enter__(self) -> Self: ... + def __exit__( + self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None + ) -> None: ... From 5ab66b81ea57d3a30293c9d87cbaebcffef513ad Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 20 Nov 2026 12:08:06 +0000 Subject: [PATCH 2/5] [pre-commit.ci] auto fixes from pre-commit.com hooks --- stubs/peewee/playhouse/test_utils.pyi | 1 - 1 file changed, 1 deletion(-) diff --git a/stubs/peewee/playhouse/test_utils.pyi b/stubs/peewee/playhouse/test_utils.pyi index a389837a13be..0ed9a9ae3d5f 100644 --- a/stubs/peewee/playhouse/test_utils.pyi +++ b/stubs/peewee/playhouse/test_utils.pyi @@ -1,6 +1,5 @@ from logging import LogRecord from types import TracebackType - from typing_extensions import Self class count_queries: From 2933a12758d55fa1c60daa7984862ad00cc98fbb Mon Sep 17 00:00:00 2001 From: Kirill Klenov Date: Fri, 20 Nov 2026 15:10:33 +0300 Subject: [PATCH 3/5] [peewee] Allow missing playhouse members in stubtest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The new playhouse extension stubs only cover a few names, so allowlist the rest and type the JSONField json_dumps/json_loads arguments. 🎂 --- stubs/peewee/@tests/stubtest_allowlist.txt | 2 ++ stubs/peewee/playhouse/sqlite_ext.pyi | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/stubs/peewee/@tests/stubtest_allowlist.txt b/stubs/peewee/@tests/stubtest_allowlist.txt index 4f13b464e2d2..0dde2407ee08 100644 --- a/stubs/peewee/@tests/stubtest_allowlist.txt +++ b/stubs/peewee/@tests/stubtest_allowlist.txt @@ -42,3 +42,5 @@ playhouse\.\w+? playhouse.flask_utils.PaginatedQuery playhouse.flask_utils.get_\w+ playhouse.flask_utils.object_list +# Only a small part of these modules is stubbed +playhouse\.(postgres_ext|sqlite_ext|test_utils)(\.\w+)* diff --git a/stubs/peewee/playhouse/sqlite_ext.pyi b/stubs/peewee/playhouse/sqlite_ext.pyi index cba4e68db7f7..c39c1e3aa049 100644 --- a/stubs/peewee/playhouse/sqlite_ext.pyi +++ b/stubs/peewee/playhouse/sqlite_ext.pyi @@ -1,9 +1,12 @@ +from collections.abc import Callable from typing import Any from peewee import Expression, TextField class JSONField(TextField[str]): - def __init__(self, json_dumps: Any = ..., json_loads: Any = ..., **kwargs: Any) -> None: ... + def __init__( + self, json_dumps: Callable[[Any], str] | None = ..., json_loads: Callable[[str], Any] | None = ..., **kwargs: Any + ) -> None: ... def db_value(self, value: Any) -> str | None: ... def python_value(self, value: str | None) -> Any: ... def children(self) -> Expression: ... From f4442cfbaa5a220baee08313fd5b403bbec689c8 Mon Sep 17 00:00:00 2001 From: Kirill Klenov Date: Mon, 23 Nov 2026 11:40:20 +0300 Subject: [PATCH 4/5] [peewee] Address review comments on playhouse stubs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Make ArrayField generic over its item type and document the Any arguments that are forwarded to the parent constructors. ◀️ --- stubs/peewee/playhouse/postgres_ext.pyi | 17 ++++++++++------- stubs/peewee/playhouse/sqlite_ext.pyi | 9 ++++++--- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/stubs/peewee/playhouse/postgres_ext.pyi b/stubs/peewee/playhouse/postgres_ext.pyi index ac70de7ce1a3..5e5d39e1658c 100644 --- a/stubs/peewee/playhouse/postgres_ext.pyi +++ b/stubs/peewee/playhouse/postgres_ext.pyi @@ -1,18 +1,21 @@ from typing import Any +from typing_extensions import TypeVar from peewee import Expression, Field -class ArrayField(Field[list[Any]]): +_T = TypeVar("_T", default=Any) + +class ArrayField(Field[list[_T]]): dimensions: int def __init__( self, - field_class: type[Field[Any]] = ..., + field_class: type[Field[_T]] = ..., field_kwargs: dict[str, Any] | None = ..., dimensions: int = 1, convert_values: bool = False, - *args: Any, - **kwargs: Any, + *args: Any, # Passed to Field.__init__ + **kwargs: Any, # Passed to Field.__init__ ) -> None: ... - def contains(self, *items: Any) -> Expression: ... - def contains_any(self, *items: Any) -> Expression: ... - def contained_by(self, *items: Any) -> Expression: ... + def contains(self, *items: _T) -> Expression: ... + def contains_any(self, *items: _T) -> Expression: ... + def contained_by(self, *items: _T) -> Expression: ... diff --git a/stubs/peewee/playhouse/sqlite_ext.pyi b/stubs/peewee/playhouse/sqlite_ext.pyi index c39c1e3aa049..2b67ec9a803b 100644 --- a/stubs/peewee/playhouse/sqlite_ext.pyi +++ b/stubs/peewee/playhouse/sqlite_ext.pyi @@ -5,10 +5,13 @@ from peewee import Expression, TextField class JSONField(TextField[str]): def __init__( - self, json_dumps: Callable[[Any], str] | None = ..., json_loads: Callable[[str], Any] | None = ..., **kwargs: Any + self, + json_dumps: Callable[[object], str] | None = ..., + json_loads: Callable[[str], object] | None = ..., + **kwargs: Any, # Passed to TextField.__init__ ) -> None: ... - def db_value(self, value: Any) -> str | None: ... - def python_value(self, value: str | None) -> Any: ... + def db_value(self, value: object) -> str | None: ... + def python_value(self, value: str | None) -> Any: ... # Decoded JSON: any JSON-compatible value def children(self) -> Expression: ... def length(self, path: str | None = None) -> Expression: ... def json_type(self) -> Expression: ... From 49d827917568ba10dcf806a9a1e2d4e6b117e8ae Mon Sep 17 00:00:00 2001 From: Kirill Klenov Date: Mon, 23 Nov 2026 11:45:26 +0300 Subject: [PATCH 5/5] [peewee] Keep Any with an explanatory comment in JSONField MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit object would reject typed json_dumps callbacks such as a dict-only serializer, and db_value accepts nodes as well as JSON values. 🦈 --- stubs/peewee/playhouse/sqlite_ext.pyi | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/stubs/peewee/playhouse/sqlite_ext.pyi b/stubs/peewee/playhouse/sqlite_ext.pyi index 2b67ec9a803b..c7d8a21fdd94 100644 --- a/stubs/peewee/playhouse/sqlite_ext.pyi +++ b/stubs/peewee/playhouse/sqlite_ext.pyi @@ -6,12 +6,12 @@ from peewee import Expression, TextField class JSONField(TextField[str]): def __init__( self, - json_dumps: Callable[[object], str] | None = ..., - json_loads: Callable[[str], object] | None = ..., + json_dumps: Callable[[Any], str] | None = ..., # Takes any JSON-serializable value + json_loads: Callable[[str], Any] | None = ..., # Returns any decoded JSON value **kwargs: Any, # Passed to TextField.__init__ ) -> None: ... - def db_value(self, value: object) -> str | None: ... - def python_value(self, value: str | None) -> Any: ... # Decoded JSON: any JSON-compatible value + def db_value(self, value: Any) -> str | None: ... # Takes any JSON-serializable value, or a Node + def python_value(self, value: str | None) -> Any: ... # Returns any decoded JSON value def children(self) -> Expression: ... def length(self, path: str | None = None) -> Expression: ... def json_type(self) -> Expression: ...