@@ -469,66 +469,62 @@ def _get_list_type_ref(inst: T) -> type[list[T]]:
469
469
item_type = type (from_list [0 ]) # type: ignore[misc]
470
470
return list [item_type ] # type: ignore[valid-type]
471
471
472
- @classmethod
473
- def _marshal (cls , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
472
+ def _marshal (self , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
474
473
"""The `_marshal` method is a private method that is used to serialize an object of type `type_ref` to
475
474
a dictionary. This method is called by the `save` method."""
475
+ if inst is None :
476
+ return None , False
477
+ if isinstance (inst , databricks .sdk .core .Config ):
478
+ return self ._marshal_databricks_config (inst )
476
479
if hasattr (inst , "as_dict" ):
477
480
return inst .as_dict (), True
478
481
if dataclasses .is_dataclass (type_ref ):
479
- return cls ._marshal_dataclass (type_ref , path , inst )
480
- if isinstance (inst , databricks .sdk .core .Config ):
481
- return inst .as_dict (), True
482
+ return self ._marshal_dataclass (type_ref , path , inst )
482
483
if type_ref == list :
483
- return cls ._marshal_list (type_ref , path , inst )
484
+ return self ._marshal_list (type_ref , path , inst )
484
485
if isinstance (type_ref , enum .EnumMeta ):
485
- return cls ._marshal_enum (inst )
486
+ return self ._marshal_enum (inst )
486
487
if type_ref == types .NoneType :
487
488
return inst , inst is None
488
- if type_ref == databricks .sdk .core .Config :
489
- return cls ._marshal_databricks_config (inst )
490
- if type_ref in cls ._PRIMITIVES :
489
+ if type_ref in self ._PRIMITIVES :
491
490
return inst , True
492
- return cls ._marshal_generic_types (type_ref , path , inst )
491
+ return self ._marshal_generic_types (type_ref , path , inst )
493
492
494
- @classmethod
495
- def _marshal_generic_types (cls , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
493
+ def _marshal_generic_types (self , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
496
494
# pylint: disable-next=import-outside-toplevel,import-private-name
497
495
from typing import ( # type: ignore[attr-defined]
498
496
_GenericAlias ,
499
497
_UnionGenericAlias ,
500
498
)
501
499
502
500
if isinstance (type_ref , (types .UnionType , _UnionGenericAlias )): # type: ignore[attr-defined]
503
- return cls ._marshal_union (type_ref , path , inst )
501
+ return self ._marshal_union (type_ref , path , inst )
504
502
if isinstance (type_ref , (_GenericAlias , types .GenericAlias )): # type: ignore[attr-defined]
505
503
if type_ref .__origin__ in (dict , list ) or isinstance (type_ref , types .GenericAlias ):
506
- return cls ._marshal_generic (type_ref , path , inst )
507
- return cls ._marshal_generic_alias (type_ref , inst )
504
+ return self ._marshal_generic (type_ref , path , inst )
505
+ return self ._marshal_generic_alias (type_ref , inst )
508
506
raise SerdeError (f'{ "." .join (path )} : unknown: { inst } ' )
509
507
510
- @classmethod
511
- def _marshal_union (cls , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
508
+ def _marshal_union (self , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
512
509
"""The `_marshal_union` method is a private method that is used to serialize an object of type `type_ref` to
513
510
a dictionary. This method is called by the `save` method."""
514
511
combo = []
515
512
for variant in get_args (type_ref ):
516
- value , ok = cls ._marshal (variant , [* path , f"(as { variant } )" ], inst )
513
+ value , ok = self ._marshal (variant , [* path , f"(as { variant } )" ], inst )
517
514
if ok :
518
515
return value , True
519
- combo .append (cls ._explain_why (variant , [* path , f"(as { variant } )" ], inst ))
516
+ combo .append (self ._explain_why (variant , [* path , f"(as { variant } )" ], inst ))
520
517
raise SerdeError (f'{ "." .join (path )} : union: { " or " .join (combo )} ' )
521
518
522
- @classmethod
523
- def _marshal_generic (cls , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
519
+ def _marshal_generic (self , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
524
520
"""The `_marshal_generic` method is a private method that is used to serialize an object of type `type_ref`
525
521
to a dictionary. This method is called by the `save` method."""
526
522
type_args = get_args (type_ref )
527
523
if not type_args :
528
524
raise SerdeError (f"Missing type arguments: { type_args } " )
529
525
if len (type_args ) == 2 :
530
- return cls ._marshal_dict (type_args [1 ], path , inst )
531
- return cls ._marshal_list (type_args [0 ], path , inst )
526
+ return self ._marshal_dict (type_args [1 ], path , inst )
527
+ return self ._marshal_list (type_args [0 ], path , inst )
532
528
533
529
@staticmethod
534
530
def _marshal_generic_alias (type_ref , inst ):
@@ -538,35 +534,32 @@ def _marshal_generic_alias(type_ref, inst):
538
534
return None , False
539
535
return inst , isinstance (inst , type_ref .__origin__ ) # type: ignore[attr-defined]
540
536
541
- @classmethod
542
- def _marshal_list (cls , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
537
+ def _marshal_list (self , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
543
538
"""The `_marshal_list` method is a private method that is used to serialize an object of type `type_ref` to
544
539
a dictionary. This method is called by the `save` method."""
545
540
as_list = []
546
541
if not isinstance (inst , list ):
547
542
return None , False
548
543
for i , v in enumerate (inst ):
549
- value , ok = cls ._marshal (type_ref , [* path , f"{ i } " ], v )
544
+ value , ok = self ._marshal (type_ref , [* path , f"{ i } " ], v )
550
545
if not ok :
551
- raise SerdeError (cls ._explain_why (type_ref , [* path , f"{ i } " ], v ))
546
+ raise SerdeError (self ._explain_why (type_ref , [* path , f"{ i } " ], v ))
552
547
as_list .append (value )
553
548
return as_list , True
554
549
555
- @classmethod
556
- def _marshal_dict (cls , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
550
+ def _marshal_dict (self , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
557
551
"""The `_marshal_dict` method is a private method that is used to serialize an object of type `type_ref` to
558
552
a dictionary. This method is called by the `save` method."""
559
553
if not isinstance (inst , dict ):
560
554
return None , False
561
555
as_dict = {}
562
556
for k , v in inst .items ():
563
- as_dict [k ], ok = cls ._marshal (type_ref , [* path , k ], v )
557
+ as_dict [k ], ok = self ._marshal (type_ref , [* path , k ], v )
564
558
if not ok :
565
- raise SerdeError (cls ._explain_why (type_ref , [* path , k ], v ))
559
+ raise SerdeError (self ._explain_why (type_ref , [* path , k ], v ))
566
560
return as_dict , True
567
561
568
- @classmethod
569
- def _marshal_dataclass (cls , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
562
+ def _marshal_dataclass (self , type_ref : type , path : list [str ], inst : Any ) -> tuple [Any , bool ]:
570
563
"""The `_marshal_dataclass` method is a private method that is used to serialize an object of type `type_ref`
571
564
to a dictionary. This method is called by the `save` method."""
572
565
if inst is None :
@@ -577,21 +570,29 @@ def _marshal_dataclass(cls, type_ref: type, path: list[str], inst: Any) -> tuple
577
570
if origin is typing .ClassVar :
578
571
continue
579
572
raw = getattr (inst , field )
580
- value , ok = cls ._marshal (hint , [* path , field ], raw )
573
+ if not raw :
574
+ continue
575
+ value , ok = self ._marshal (hint , [* path , field ], raw )
581
576
if not ok :
582
- raise SerdeError (cls ._explain_why (hint , [* path , field ], raw ))
577
+ raise SerdeError (self ._explain_why (hint , [* path , field ], raw ))
583
578
if not value :
584
579
continue
585
580
as_dict [field ] = value
586
581
return as_dict , True
587
582
588
- @staticmethod
589
- def _marshal_databricks_config (inst ):
583
+ def _marshal_databricks_config (self , inst ):
590
584
"""The `_marshal_databricks_config` method is a private method that is used to serialize an object of type
591
585
`databricks.sdk.core.Config` to a dictionary. This method is called by the `save` method."""
592
586
if not inst :
593
587
return None , False
594
- return inst .as_dict (), True
588
+ current_client_config = self ._current_client_config ()
589
+ remote_file_config = inst .as_dict ()
590
+ if current_client_config == remote_file_config :
591
+ return None , True
592
+ return remote_file_config , True
593
+
594
+ def _current_client_config (self ) -> dict :
595
+ return self ._ws .config .as_dict ()
595
596
596
597
@staticmethod
597
598
def _marshal_enum (inst ):
@@ -886,6 +887,9 @@ def files(self) -> list[workspace.ObjectInfo]:
886
887
def remove (self ):
887
888
self ._removed = True
888
889
890
+ def _current_client_config (self ) -> dict :
891
+ return {}
892
+
889
893
def _overwrite_content (self , filename : str , as_dict : Json , type_ref : type ):
890
894
self ._overwrites [filename ] = as_dict
891
895
0 commit comments