Skip to content

Commit 223aa82

Browse files
committed
remove mutable default; only save create
1 parent fa626f9 commit 223aa82

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

fastcore/foundation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,17 @@ def read_config_file(file, **kwargs):
249249
# %% ../nbs/02_foundation.ipynb 131
250250
class Config:
251251
"Reading and writing `ConfigParser` ini files"
252-
def __init__(self, cfg_path, cfg_name, create=None, save=True, extra_files=[]):
252+
def __init__(self, cfg_path, cfg_name, create=None, save=True, extra_files=None):
253253
cfg_path = Path(cfg_path).expanduser().absolute()
254254
self.config_path,self.config_file = cfg_path,cfg_path/cfg_name
255255
self._cfg = ConfigParser()
256256
self.d = self._cfg['DEFAULT']
257-
found = [Path(o) for o in self._cfg.read(extra_files+[self.config_file])]
257+
found = [Path(o) for o in self._cfg.read(L(extra_files)+[self.config_file])]
258258
if self.config_file not in found and create is not None:
259259
self._cfg.read_dict({'DEFAULT':create})
260260
if save:
261261
cfg_path.mkdir(exist_ok=True, parents=True)
262-
self.save()
262+
save_config_file(self.config_file, create)
263263

264264
def __repr__(self): return repr(dict(self._cfg.items('DEFAULT', raw=True)))
265265
def __setitem__(self,k,v): self.d[k] = str(v)

nbs/02_foundation.ipynb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2004,17 +2004,17 @@
20042004
"#|export\n",
20052005
"class Config:\n",
20062006
" \"Reading and writing `ConfigParser` ini files\"\n",
2007-
" def __init__(self, cfg_path, cfg_name, create=None, save=True, extra_files=[]):\n",
2007+
" def __init__(self, cfg_path, cfg_name, create=None, save=True, extra_files=None):\n",
20082008
" cfg_path = Path(cfg_path).expanduser().absolute()\n",
20092009
" self.config_path,self.config_file = cfg_path,cfg_path/cfg_name\n",
20102010
" self._cfg = ConfigParser()\n",
20112011
" self.d = self._cfg['DEFAULT']\n",
2012-
" found = [Path(o) for o in self._cfg.read(extra_files+[self.config_file])]\n",
2012+
" found = [Path(o) for o in self._cfg.read(L(extra_files)+[self.config_file])]\n",
20132013
" if self.config_file not in found and create is not None:\n",
20142014
" self._cfg.read_dict({'DEFAULT':create})\n",
20152015
" if save:\n",
20162016
" cfg_path.mkdir(exist_ok=True, parents=True)\n",
2017-
" self.save()\n",
2017+
" save_config_file(self.config_file, create)\n",
20182018
"\n",
20192019
" def __repr__(self): return repr(dict(self._cfg.items('DEFAULT', raw=True)))\n",
20202020
" def __setitem__(self,k,v): self.d[k] = str(v)\n",
@@ -2040,7 +2040,7 @@
20402040
"cell_type": "markdown",
20412041
"metadata": {},
20422042
"source": [
2043-
"Instantiate a `Config` from a ini file at `cfg_path/cfg_name`:"
2043+
"Instantiate a `Config` from an ini file at `cfg_path/cfg_name`:"
20442044
]
20452045
},
20462046
{

0 commit comments

Comments
 (0)