versioned
Version
Bases: Tuple[int, ...]
Class representing a version as a tuple of integers.
Source code in fancy_dataclass/versioned.py
__new__(version)
Constructs a Version from a single integer, tuple of integers, or .-separated version string.
Source code in fancy_dataclass/versioned.py
VersionedDataclass
dataclass
Bases: DictDataclass
Mixin class that ensures a version integer is associated with a given dataclass type.
This enables reliable migration between different versions of the "same" class.
This class also inherits from [DictDataclass](fancy_dataclass.dict.DictDataclass], providing support for dict conversion, where by default the version field will be included in the dict representation.
Source code in fancy_dataclass/versioned.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 | |
dataclass_args_from_dict(d)
classmethod
Given a dict of arguments, performs type conversion and/or validity checking, then returns a new dict that can be passed to the class's constructor.
Source code in fancy_dataclass/versioned.py
from_dict(d, *, migrate=False, **kwargs)
classmethod
Constructs an object from a dictionary of fields.
This may also perform some basic type/validity checking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
d
|
AnyDict
|
Dict to convert into an object |
required |
migrate
|
bool
|
If |
False
|
kwargs
|
Any
|
Keyword arguments |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
Converted object of this class |
Source code in fancy_dataclass/versioned.py
get_class_with_version(version=None)
classmethod
Gets the corresponding class to this class with the given version.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
Optional[AnyVersion]
|
Version of the class to retrieve from the global registry (if |
None
|
Source code in fancy_dataclass/versioned.py
migrate(version=None)
Migrates the object to a class corresponding to a (possibly different) version of this class, if possible.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
Optional[AnyVersion]
|
Version of the class to migrate to (if |
None
|
Source code in fancy_dataclass/versioned.py
VersionedDataclassSettings
Bases: DictDataclassSettings
Class-level settings for the VersionedDataclass mixin.
Subclasses of VersionedDataclass should set the version field to an integer, integer tuple, or .-separated string indicating the version.
Additionally they may set the following options as keyword arguments during inheritance:
suppress_version: suppress version field when converting to a dict
Source code in fancy_dataclass/versioned.py
version(version, suppress_version=False)
Decorator turning a regular dataclass into a VersionedDataclass.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
version
|
AnyVersion
|
Version associated with the class (integer, integer tuple, or |
required |
suppress_version
|
bool
|
Whether to suppress the version when converting to dict |
False
|
Returns:
| Type | Description |
|---|---|
Callable[[Type[T]], Type[T]]
|
Decorator to wrap a |