Custom serializer with Optional (aka | None) #436
Answered
by
yukinarit
davetapley
asked this question in
Q&A
-
I think I can workaround with e.g.: def field_timedelta():
return field(
serializer=lambda s: None if s is None else parse_duration(s))
@dataclass
class ReportConfig:
schedule: timedelta | None = field_timedelta() But I wonder if there's a better way? 🤔 |
Beta Was this translation helpful? Give feedback.
Answered by
yukinarit
Oct 18, 2023
Replies: 1 comment 1 reply
-
One problem with that workaround is that I can't make |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about using
*args
and**kwargs
?