Skip to content

[peewee] Add stubs for playhouse extension modules - #16878

Open
klen wants to merge 3 commits into
python:mainfrom
klen:playhouse-extension-stubs
Open

klen wants to merge 3 commits into
python:mainfrom
klen:playhouse-extension-stubs

Conversation

@klen

@klen klen commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

The peewee stubs are a partial stub, but playhouse.sqlite_ext, playhouse.postgres_ext and playhouse.test_utils are commonly used and currently resolve to Any (or fail as untyped calls under stricter checkers). This adds stubs for sqlite_ext.JSONField, postgres_ext.ArrayField and test_utils.count_queries, matching the runtime implementations.

Upstream: https://github.com/coleifer/peewee/blob/master/playhouse/sqlite_ext.py, https://github.com/coleifer/peewee/blob/master/playhouse/postgres_ext.py, https://github.com/coleifer/peewee/blob/master/playhouse/test_utils.py

Written with pi.

klen and others added 3 commits November 20, 2026 15:05
Cover playhouse.sqlite_ext.JSONField, playhouse.postgres_ext.ArrayField
and playhouse.test_utils.count_queries, which were missing from the
partial stubs. 🖇
The new playhouse extension stubs only cover a few names, so allowlist
the rest and type the JSONField json_dumps/json_loads arguments. 🎂
@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@srittau srittau left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a full review, just a few things I noticed.

Comment on lines +13 to +14
*args: Any,
**kwargs: Any,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, Any needs a comment explaining allowed types or how the item is used. (Field[Any] and dict[str, Any] are exceptions, since they are obvious.)


from peewee import Expression, Field

class ArrayField(Field[list[Any]]):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make more sense to make ArrayField generic over the type of the list items?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants