-
Notifications
You must be signed in to change notification settings - Fork 22
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
Generate mypy types #7
Comments
Hi @jdahlin, Sounds interesting, what would be an example of the input and generated output? Thank you 👍 |
Something like this, completely untested but to give you an idea. Input: class QueueTextGenerationItem(serializers.DictField):
channel_id = serializers.IntegerField()
language_code = serializers.CharField()
product_id = serializers.CharField()
force_regenerate = serializers.BooleanField(required=False)
class QueueTextGenerationRequest(serializers.Serializer):
generation_requests = serializers.ListField(child=QueueTextGenerationItem())
text_status = serializers.CharField() Output: from typing import List
from typing_extensions import TypedDict
class QueueTextGenerationItem(TypedDict):
channel_id: int
language_code: str
channel_id: str
force_regenerate: Optional[bool]
class QueueTextGenerationRequest(TypedDict):
generation_requests: List[QueueTextGenerationItem]
text_status: str |
Hi @jdahlin, Looks simple enough actually, I'll try knock this one at lunch time today (it's ~8:40 AM here). Thanks for the suggestion! 👍 |
Hi @jdahlin, I've determined that this might actually be difficult to implement without introducing breaking changes, so I'll do a bit more analysis. Ideally, I'll add the ability to support a number of different generators (Typescript, MyPy, etc) based on an abstract class. Keeping this issue open, since I intend to add this support 👍 |
It would be nice to have the option to generate mypy types in addition to TypeScript definitions.
The use case would allow you to pass around typed dictionaries in Python code that is either passed into or returned from a DRF Serializer.
The text was updated successfully, but these errors were encountered: