@@ -196,7 +196,7 @@ def __init__(
196196
197197 @classmethod
198198 def load (cls , filename : Union [str , Path ]) -> "Workspace" :
199- """Load a workspace from a file (which may optionally be gzipped)."""
199+ """Load a workspace from a JSON file (which may optionally be gzipped)."""
200200 filename = Path (filename )
201201 try :
202202 with gzip .open (filename , "rt" ) as handle :
@@ -217,20 +217,25 @@ def dump(
217217 self ,
218218 filename : Union [str , Path ],
219219 * ,
220- zip : bool = False ,
220+ zip : Optional [ bool ] = None ,
221221 indent : Optional [int ] = None ,
222222 ** kwargs
223223 ):
224224 """
225- Save a workspace to a file, optionally zipped.
225+ Save a workspace as JSON to a file, optionally gzipped.
226+
227+ By default, filenames ending with `.gz` will be zipped and anything else won't,
228+ however this can be overridden by explicitly passing the `zip` argument.
226229
227230 Arguments:
228- filename (str/Path) : filename to write to.
229- zip (bool) : if true then contents will be zipped with GZip .
230- indent (int) : if specified then pretty-print the JSON with given indent.
231+ filename: filename to write to.
232+ zip: if specified then controls whether the contents are gzipped .
233+ indent: if specified then pretty-print the JSON with given indent.
231234 kwargs: other arguments to pass through to `json.dumps()`.
232235 """
233236 filename = Path (filename )
237+ if zip is None :
238+ zip = str (filename ).endswith (".gz" )
234239 with gzip .open (filename , "wt" ) if zip else filename .open ("wt" ) as handle :
235240 handle .write (self .dumps (indent = indent , ** kwargs ))
236241
0 commit comments