[peewee] add typed fields, queries, and update to some of the new APIs#15911
[peewee] add typed fields, queries, and update to some of the new APIs#15911coleifer wants to merge 9 commits into
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
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). |
|
A general comment: Non-obvious default: Any # Accepted types depend on the field type(I'm not sure whether that's the correct explanation.) |
|
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
|
@srittau / team - it really would be fantastic to hear what remaining blockers there are from your side. These changes, I believe, will seriously improve the utility of the stub for Peewee users. Like Django and others, we have a really dynamic API and use metaclass magic and descriptors for field access. These changes address differentiating The distribution channel for a second/separate set of stubs is just not there, IMO, so I'm really hoping that these changes can get upstreamed. I can go into more detail about this if you wish, but I think the best value and least pain for existing users is typeshed. |
Attempt to get Peewee's typing a little bit nicer and bring in some of the additions since 4.0.5.
Added:
For field access - peewee uses metaclass magic along with descriptors, kinda like Django. Fields are now generic over their Python value, so
Model.fieldis the field instance for building queries, andinstance.fieldis the value (e.g. str for CharField, related model for a ForeignKeyField, etc). Also specifyingnull=Truemakes the instance value optional, which is nice.