Skip to content

Commit c1263dd

Browse files
committed
added _ENCODER_FILE_FORMAT_VERSION_COMPATIBILITY in case future updates use different format
1 parent 0a51cd2 commit c1263dd

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

pyvisim/encoders/_base_encoder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020

2121
_ENCODER_FILE_SUFFIX = ".encoder"
2222
_ENCODER_FILE_FORMAT_VERSION = 1
23+
_ENCODER_FILE_FORMAT_VERSION_COMPATIBILITY: dict[tuple[int, int], bool] = {
24+
# TODO: when the next _ENCODER_FILE_FORMAT_VERSION comes, check if
25+
# it's forward / backward compatible, then add entries like:
26+
# (1, 2): True, # version 1 can read files from version 2
27+
#
28+
# However, (2, 1) might not be True!!
29+
}
2330
_ENCODER_STATE_KEYS = frozenset(
2431
{
2532
"encoder_class",
@@ -530,6 +537,8 @@ def load_from_disk(
530537
state = joblib.load(path)
531538
if not isinstance(state, dict) or not _ENCODER_STATE_KEYS.issubset(state):
532539
raise ValueError(f"File {path} is not a valid .encoder file.")
540+
# TODO: in the future, verify format version by checking
541+
# compatibility via _ENCODER_FILE_FORMAT_VERSION_COMPATIBILITY
533542
if state["encoder_class"] != cls.__name__:
534543
raise ValueError(
535544
f"File {path} was saved by {state['encoder_class']}. "

0 commit comments

Comments
 (0)