Unverified Commit 1cd864d6 authored by Alex Yang's avatar Alex Yang Committed by GitHub
Browse files

[Feature] Support shallow copy for Config (#1796)



* Add .owners.yml to mark daily issue shift

* Update .owners.yml

fix end of file

* Add __copy__() to Config

* fix format in config.py

* fix format in test_copy

* fix format in config.py

* Update config.py

* Update tests/test_utils/test_config.py
Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>
Co-authored-by: default avatarZaida Zhou <58739961+zhouzaida@users.noreply.github.com>
parent b5d550f0
...@@ -528,6 +528,13 @@ class Config: ...@@ -528,6 +528,13 @@ class Config:
def __getstate__(self): def __getstate__(self):
return (self._cfg_dict, self._filename, self._text) return (self._cfg_dict, self._filename, self._text)
def __copy__(self):
cls = self.__class__
other = cls.__new__(cls)
other.__dict__.update(self.__dict__)
return other
def __deepcopy__(self, memo): def __deepcopy__(self, memo):
cls = self.__class__ cls = self.__class__
other = cls.__new__(cls) other = cls.__new__(cls)
......
...@@ -549,3 +549,15 @@ def test_deepcopy(): ...@@ -549,3 +549,15 @@ def test_deepcopy():
assert new_cfg._cfg_dict is not cfg._cfg_dict assert new_cfg._cfg_dict is not cfg._cfg_dict
assert new_cfg._filename == cfg._filename assert new_cfg._filename == cfg._filename
assert new_cfg._text == cfg._text assert new_cfg._text == cfg._text
def test_copy():
cfg_file = osp.join(data_path, 'config/n.py')
cfg = Config.fromfile(cfg_file)
new_cfg = copy.copy(cfg)
assert isinstance(new_cfg, Config)
assert new_cfg is not cfg
assert new_cfg._cfg_dict is cfg._cfg_dict
assert new_cfg._filename == cfg._filename
assert new_cfg._text == cfg._text
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment