-
Notifications
You must be signed in to change notification settings - Fork 4
Type conversion design
Toby Fleming edited this page Apr 9, 2021
·
1 revision
Can type conversion be implemented sanely? There are several issues:
- Would converters be declared in
Options
(pro: specify each converter once, con: runtime errors) or on the fields? - What does a default converter look like for a boolean? only
true
andfalse
(exception otherwise)? YAML-like? - Similarly, is it okay for
float
orint
converters to be lossy or not round-trip? Does that happen in Python, e.g. if a high-precisionfloat
is converted to astr
? - How would the logic for a
Union
look like? Try the converter for each type in the union in order? If so, how isNone
/Optional
handled? - How would type converters interact with child declarations? Would the order have to be reversed? (First try and resolve a type hint down to one or more
XmlDataclass
, and if that fails, assume it's an attribute with a converter?) - Can Mypy be prevented from subtyping converter arguments to
object
?