Skip to content

[peewee] add typed fields, queries, and update to some of the new APIs#15911

Open
coleifer wants to merge 8 commits into
python:mainfrom
coleifer:peewee-typed-fields
Open

[peewee] add typed fields, queries, and update to some of the new APIs#15911
coleifer wants to merge 8 commits into
python:mainfrom
coleifer:peewee-typed-fields

Conversation

@coleifer

@coleifer coleifer commented Jun 13, 2026

Copy link
Copy Markdown

Attempt to get Peewee's typing a little bit nicer and bring in some of the additions since 4.0.5.

Added:

  • JSONField + associated methods
  • Make field access on model class vs model instance work (see note)
  • Also get Field init params working properly for field-specific kwargs
  • Add typing to query results
  • Add typing to a handful of the chainable methods

For field access - peewee uses metaclass magic along with descriptors, kinda like Django. Fields are now generic over their Python value, so Model.field is the field instance for building queries, and instance.field is the value (e.g. str for CharField, related model for a ForeignKeyField, etc). Also specifying null=True makes the instance value optional, which is nice.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

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

@coleifer

Copy link
Copy Markdown
Author

Alrighty, I think this one's ready for review any time. Let me know if you have any q's or feedback - I think these changes will massively improve ergonomics for peewee users (all 3 of us lol).

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.

1 participant