File tree Expand file tree Collapse file tree 2 files changed +48
-7
lines changed Expand file tree Collapse file tree 2 files changed +48
-7
lines changed Original file line number Diff line number Diff line change @@ -1486,10 +1486,15 @@ def from_dict(dct: Dict[str, Any]) -> AbstractFileSystem:
1486
1486
1487
1487
json_decoder = FilesystemJSONDecoder ()
1488
1488
1489
- def deserialize (obj : Any ):
1489
+ def deserialize (obj : Any ) -> Any :
1490
1490
if isinstance (obj , dict ):
1491
- return json_decoder .custom_object_hook (obj )
1492
-
1491
+ obj = json_decoder .custom_object_hook (obj )
1492
+ if isinstance (obj , dict ):
1493
+ return {k : deserialize (v ) for k , v in obj .items ()}
1494
+
1495
+ if isinstance (obj , (list , tuple )):
1496
+ return [deserialize (v ) for v in obj ]
1497
+
1493
1498
return obj
1494
1499
1495
1500
dct = dict (dct ) # Defensive copy
@@ -1501,10 +1506,10 @@ def deserialize(obj: Any):
1501
1506
dct .pop ("cls" , None )
1502
1507
dct .pop ("protocol" , None )
1503
1508
1504
- args = tuple ( deserialize ( arg ) for arg in dct . pop ( "args" , ()))
1505
- kwargs = { k : deserialize (v ) for k , v in dct .items ()}
1506
-
1507
- return cls ( * args , ** kwargs )
1509
+ return cls (
1510
+ * deserialize (dct .pop ( "args" , ())),
1511
+ ** deserialize ( dct ),
1512
+ )
1508
1513
1509
1514
def _get_pyarrow_filesystem (self ):
1510
1515
"""
Original file line number Diff line number Diff line change @@ -891,6 +891,24 @@ def test_json_fs_attr():
891
891
assert DummyTestFS .from_json (outc ) is c
892
892
893
893
894
+ def test_json_dict_attr ():
895
+ a = DummyTestFS (1 )
896
+ b = DummyTestFS (2 , bar = Path ("baz" ))
897
+ c = DummyTestFS (3 , baz = {"key" : b })
898
+
899
+ outa = a .to_json ()
900
+ outb = b .to_json ()
901
+ outc = c .to_json ()
902
+
903
+ assert json .loads (outc ) # is valid JSON
904
+ assert b != c
905
+ assert "baz" in outc
906
+
907
+ assert DummyTestFS .from_json (outa ) is a
908
+ assert DummyTestFS .from_json (outb ) is b
909
+ assert DummyTestFS .from_json (outc ) is c
910
+
911
+
894
912
def test_dict ():
895
913
a = DummyTestFS (1 )
896
914
b = DummyTestFS (2 , bar = 1 )
@@ -939,6 +957,24 @@ def test_dict_fs_attr():
939
957
assert DummyTestFS .from_dict (outc ) is c
940
958
941
959
960
+ def test_dict_dict_attr ():
961
+ a = DummyTestFS (1 )
962
+ b = DummyTestFS (2 , bar = Path ("baz" ))
963
+ c = DummyTestFS (3 , baz = {"key" : b })
964
+
965
+ outa = a .to_dict ()
966
+ outb = b .to_dict ()
967
+ outc = c .to_dict ()
968
+
969
+ assert isinstance (outc , dict )
970
+ assert b != c
971
+ assert outc ["baz" ]["key" ] == outb
972
+
973
+ assert DummyTestFS .from_dict (outa ) is a
974
+ assert DummyTestFS .from_dict (outb ) is b
975
+ assert DummyTestFS .from_dict (outc ) is c
976
+
977
+
942
978
def test_dict_idempotent ():
943
979
a = DummyTestFS (1 )
944
980
You can’t perform that action at this time.
0 commit comments