Guide for typing custom Fields #2170
martinlehoux
started this conversation in
Common issues and solutions
Replies: 1 comment
-
#1900 would really help, however to be even more user friendly with subclasses, it will require some work on the mypy side. I'll see if I can make some progress here |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello!
I'm struggling to make a pattern work, but I think it's a common pattern in Django. I would like help to implement this correctly, then I can add it as a FAQ item.
My question is : how can I implement the correct typing for a custom model Field in Django?
I have a simple wrapper around postgres
DateRange
fieldI also have this typing override
date_range = EnhancedDateRangeField(null=True)
. At this point, I getEnhancedDateRangeField is nullable but its generic get type parameter is not optional
EnhancedDateRange
in my typing override with a typevarTEnhanced = TypeVar("TEnhancedDateRange", bound=EnhancedDateRange | None)
, but then it requires to add type annotations to all usage ofEnhancedDateRangeField
DateRange
Beta Was this translation helpful? Give feedback.
All reactions