File tree Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Expand file tree Collapse file tree 1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -211,8 +211,20 @@ def _collect_global_attrs(self, obj):
211211 self .file_content [fc_key ] = global_attrs [key ] = value
212212 self .file_content ["/attrs" ] = global_attrs
213213
214- def _get_object_attrs (self , obj ):
215- return obj .__dict__
214+ @staticmethod
215+ def _get_object_attrs (obj ):
216+ """Get object attributes using __dict__ but retrieve recoverable attributes on failure."""
217+ try :
218+ return obj .__dict__
219+ except KeyError :
220+ # Maybe unrecognised datatype.
221+ atts = {}
222+ for attname in obj .ncattrs ():
223+ try :
224+ atts [attname ] = obj .getncattr (attname )
225+ except KeyError :
226+ LOG .warning (f"Warning: Cannot load object ({ obj .name } ) attribute ({ attname } )." )
227+ return atts
216228
217229 def _collect_attrs (self , name , obj ):
218230 """Collect all the attributes for the provided file object."""
You can’t perform that action at this time.
0 commit comments