Datasets:

ArXiv:
Elron commited on
Commit
b9ff862
1 Parent(s): 583a179

Upload artifact.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. artifact.py +17 -1
artifact.py CHANGED
@@ -207,7 +207,7 @@ class Artifact(Dataclass):
207
 
208
  @final
209
  def __pre_init__(self, **kwargs):
210
- self._init_dict = deepcopy(kwargs)
211
 
212
  @final
213
  def __post_init__(self):
@@ -232,6 +232,22 @@ class Artifact(Dataclass):
232
  save_json(path, data)
233
 
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
  class ArtifactList(list, Artifact):
236
  def prepare(self):
237
  for artifact in self:
 
207
 
208
  @final
209
  def __pre_init__(self, **kwargs):
210
+ self._init_dict = get_raw(kwargs)
211
 
212
  @final
213
  def __post_init__(self):
 
232
  save_json(path, data)
233
 
234
 
235
+ def get_raw(obj):
236
+ if isinstance(obj, Artifact):
237
+ return obj._to_raw_dict()
238
+
239
+ if isinstance(obj, tuple) and hasattr(obj, "_fields"): # named tuple
240
+ return type(obj)(*[get_raw(v) for v in obj])
241
+
242
+ if isinstance(obj, (list, tuple)):
243
+ return type(obj)([get_raw(v) for v in obj])
244
+
245
+ if isinstance(obj, dict):
246
+ return type(obj)({get_raw(k): get_raw(v) for k, v in obj.items()})
247
+
248
+ return deepcopy(obj)
249
+
250
+
251
  class ArtifactList(list, Artifact):
252
  def prepare(self):
253
  for artifact in self: