11import re
2- from typing import Any , ClassVar , Self
2+ from typing import Any , ClassVar , Self , Annotated
33
44from packaging .version import Version
55import euklid
@@ -100,6 +100,14 @@ class SewingAllowanceConfig(ConfigTable):
100100 entry : Length = Length ("10mm" )
101101 folded : Length = Length ("10mm" )
102102
103+ def validate_version (version : Version | str ) -> Version :
104+ if isinstance (version , str ):
105+ return Version (version )
106+
107+ return version
108+
109+ VersionType = Annotated [Version , pydantic .BeforeValidator (validate_version )]
110+
103111class ParametricGliderConfig (ConfigTable ):
104112 table_name = "Data"
105113
@@ -125,14 +133,19 @@ class ParametricGliderConfig(ConfigTable):
125133 use_sag : bool = True
126134 baseline_pct : Percentage = Percentage (0. )
127135
128- version : Version = Version (__version__ )
136+ version : VersionType = Version (__version__ )
129137
130138 @classmethod
131139 def __from_json__ (cls , ** data : Any ) -> Self :
132140 for name in "pilot_position" , "brake_offset" :
133141 data [name ] = euklid .vector .Vector3D (data [name ])
134142
135143 return cls (** data )
144+
145+ def __json__ (self ) -> dict [str , Any ]:
146+ data = super ().__json__ ()
147+ data ["version" ] = str (self .version )
148+ return data
136149
137150 def get_lower_attachment_points (self ) -> dict [str , Node ]:
138151 points = {
0 commit comments