You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from __future__ importannotationsfromdataclassesimportdataclassfromhowardimportfrom_dict, to_dict@dataclassclassNumber:
value: intd= {'value': 1}
from_dict(d, Number)
# TypeError: Unsupported type int
The error message is strange, because of course ints are supported! Here's what's actually happening: The Field object, who's type attribute we inspect as part of the loading routine, is usually a genuine python type. When annotations is imported, that attribute becomes a string representing the type instead.
fromdataclassesimportfieldsfields(Number)[0].type# 'int'
I'm not sure how to fix this, so I'm just leaving this issue here.
There is an issue on the Python bug tracker here, but it doesn't look very positive.
The text was updated successfully, but these errors were encountered:
Ogaday
changed the title
Warning: from __future__ import annotations breaks from_dict
Warning: "from __future__ import annotations" breaks "from_dict"
May 28, 2020
eg:
The error message is strange, because of course ints are supported! Here's what's actually happening: The
Field
object, who'stype
attribute we inspect as part of the loading routine, is usually a genuine python type. Whenannotations
is imported, that attribute becomes a string representing the type instead.I'm not sure how to fix this, so I'm just leaving this issue here.
There is an issue on the Python bug tracker here, but it doesn't look very positive.
The text was updated successfully, but these errors were encountered: