Skip to content

Commit 9da1480

Browse files
authored
Merge pull request #451 from Salehbigdeli/Fix-AttrDict-copy
New method: `AttrDict.copy`, to return AttrDict instead of plain python dict
2 parents 6eefae3 + 99988b9 commit 9da1480

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

fastcore/_modidx.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
'version': '1.5.15'},
3333
'syms': { 'fastcore.all': {},
3434
'fastcore.basics': { 'fastcore.basics.AttrDict': 'https://fastcore.fast.ai/basics.html#attrdict',
35+
'fastcore.basics.AttrDict.copy': 'https://fastcore.fast.ai/basics.html#attrdict.copy',
3536
'fastcore.basics.Float': 'https://fastcore.fast.ai/basics.html#float',
3637
'fastcore.basics.GetAttr': 'https://fastcore.fast.ai/basics.html#getattr',
3738
'fastcore.basics.GetAttrBase': 'https://fastcore.fast.ai/basics.html#getattrbase',
@@ -397,7 +398,13 @@
397398
'fastcore.transform.get_func': 'https://fastcore.fast.ai/transform.html#get_func',
398399
'fastcore.transform.mk_transform': 'https://fastcore.fast.ai/transform.html#mk_transform'},
399400
'fastcore.utils': {},
400-
'fastcore.xdg': { 'fastcore.xdg.xdg_cache_home': 'https://fastcore.fast.ai/xdg.html#xdg_cache_home',
401+
'fastcore.xdg': { 'fastcore.xdg.XDG_CACHE_HOME': 'https://fastcore.fast.ai/xdg.html#xdg_cache_home',
402+
'fastcore.xdg.XDG_CONFIG_DIRS': 'https://fastcore.fast.ai/xdg.html#xdg_config_dirs',
403+
'fastcore.xdg.XDG_CONFIG_HOME': 'https://fastcore.fast.ai/xdg.html#xdg_config_home',
404+
'fastcore.xdg.XDG_DATA_DIRS': 'https://fastcore.fast.ai/xdg.html#xdg_data_dirs',
405+
'fastcore.xdg.XDG_DATA_HOME': 'https://fastcore.fast.ai/xdg.html#xdg_data_home',
406+
'fastcore.xdg.XDG_RUNTIME_DIR': 'https://fastcore.fast.ai/xdg.html#xdg_runtime_dir',
407+
'fastcore.xdg.xdg_cache_home': 'https://fastcore.fast.ai/xdg.html#xdg_cache_home',
401408
'fastcore.xdg.xdg_config_dirs': 'https://fastcore.fast.ai/xdg.html#xdg_config_dirs',
402409
'fastcore.xdg.xdg_config_home': 'https://fastcore.fast.ai/xdg.html#xdg_config_home',
403410
'fastcore.xdg.xdg_data_dirs': 'https://fastcore.fast.ai/xdg.html#xdg_data_dirs',

fastcore/basics.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,7 @@ def __getattr__(self,k): return self[k] if k in self else stop(AttributeError(k)
243243
def __setattr__(self, k, v): (self.__setitem__,super().__setattr__)[k[0]=='_'](k,v)
244244
def __dir__(self): return super().__dir__() + list(self.keys())
245245
def _repr_markdown_(self): return f'```json\n{pprint.pformat(self, indent=2)}\n```'
246+
def copy(self): return AttrDict(**self)
246247

247248
# %% ../nbs/01_basics.ipynb 103
248249
def get_annotations_ex(obj, *, globals=None, locals=None):

nbs/01_basics.ipynb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,8 @@
13611361
" def __getattr__(self,k): return self[k] if k in self else stop(AttributeError(k))\n",
13621362
" def __setattr__(self, k, v): (self.__setitem__,super().__setattr__)[k[0]=='_'](k,v)\n",
13631363
" def __dir__(self): return super().__dir__() + list(self.keys())\n",
1364-
" def _repr_markdown_(self): return f'```json\\n{pprint.pformat(self, indent=2)}\\n```'"
1364+
" def _repr_markdown_(self): return f'```json\\n{pprint.pformat(self, indent=2)}\\n```'\n",
1365+
" def copy(self): return AttrDict(**self)"
13651366
]
13661367
},
13671368
{

0 commit comments

Comments
 (0)