Skip to content

Commit d0fa9c9

Browse files
committed
feat: allow save_data to accept an Adaptor
1 parent 1d5c47f commit d0fa9c9

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

pins/boards.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ def _create_meta(
754754
else:
755755
p_obj = str(Path(pin_dir_path) / object_name)
756756
# file is saved locally in order to hash, calc size
757-
file_names = save_data(x._d, p_obj, type, apply_suffix)
757+
file_names = save_data(x, p_obj, type, apply_suffix)
758758

759759
meta = self.meta_factory.create(
760760
pin_dir_path,

pins/drivers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from pathlib import Path
33
from typing import Any
44

5-
from pins._adaptors import _create_adaptor
5+
from pins._adaptors import _Adaptor, _create_adaptor
66

77
from .config import PINS_ENV_INSECURE_READ, get_allow_pickle_read
88
from .errors import PinsInsecureReadError
@@ -120,7 +120,7 @@ def load_data(
120120

121121

122122
def save_data(
123-
obj, fname, pin_type=None, apply_suffix: bool = True
123+
obj: "_Adaptor | Any", fname, pin_type=None, apply_suffix: bool = True
124124
) -> "str | Sequence[str]":
125125
# TODO: extensible saving with deferred importing
126126
# TODO: how to encode arguments to saving / loading drivers?
@@ -129,7 +129,10 @@ def save_data(
129129
# as argument to board, and then type dispatchers for explicit cases
130130
# of saving / loading objects different ways.
131131

132-
adaptor = _create_adaptor(obj)
132+
if isinstance(obj, _Adaptor):
133+
adaptor, obj = obj, obj._d
134+
else:
135+
adaptor = _create_adaptor(obj)
133136

134137
if apply_suffix:
135138
if pin_type == "file":

0 commit comments

Comments
 (0)