Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Annotate Python serializer objects by TypedDict #2081

Open
paduszyk opened this issue Apr 22, 2024 · 1 comment
Open

Annotate Python serializer objects by TypedDict #2081

paduszyk opened this issue Apr 22, 2024 · 1 comment

Comments

@paduszyk
Copy link

I was recently working with django.core.serializers.python module. It implements both serializer and deserializer classes that enable export/import the Django ORM objects into/from "Python objects". Such an object is actually as dict with a hard-coded set of keys: model (lower-case model label, str), pk (the actual object's database PK value) and fields (a dict with fields names mapped onto their serialized values). Currently, the objects are annotated by dict[str, Any].

If one considered adding some wrappers around the mentioned classes (those in django.core.serializers.json are examples) from django.core.serializers.python, it would be nice to have those "objects" fully annotated, e.g. using TypedDict, something like:

from typing import Any, NotRequired, TypedDict

class PythonSerializedObject(TypedDict):
    model: str
    pk: NotRequired[Any]  # python >= (3, 11)
    fields: dict[str, Any]

I hope you will find this idea interesting.

Anyway, I thank all the developers and maintainers of the projects. This is truly a great job done! ❤️

@sobolevn
Copy link
Member

sobolevn commented Apr 22, 2024

We can always try! If you want to work on this :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants