Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] Fix ConfigDict.items will be called during dump #1272

Merged
merged 5 commits into from
Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions mmengine/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@

from mmengine.fileio import dump, load
from mmengine.logging import print_log
from mmengine.utils import (check_file_exist, get_installed_path,
import_modules_from_strings, is_installed)
from mmengine.utils import (check_file_exist, digit_version,
get_installed_path, import_modules_from_strings,
is_installed)
from .lazy import LazyAttr, LazyObject
from .utils import (ConfigParsingError, ImportTransformer, RemoveAssignFromAST,
_gather_abs_import_lazyobj, _get_external_cfg_base_path,
Expand Down Expand Up @@ -264,15 +265,18 @@ def _merge_a_into_b(a, b):
for key, value in merged.items():
self[key] = value

def __getstate__(self):
state = {}
for key, value in super().items():
state[key] = value
return state

def __setstate__(self, state):
for key, value in state.items():
self[key] = value
def __reduce_ex__(self, proto):
# Override __reduce_ex__ to avoid `self.items` will be
# called by CPython interpreter during pickling. See more details in
# https://github.com/python/cpython/blob/8d61a71f9c81619e34d4a30b625922ebc83c561b/Objects/typeobject.c#L6196 # noqa: E501
if digit_version(platform.python_version()) < digit_version('3.8'):
return (self.__class__, ({k: v
for k, v in super().items()}, ), None,
None, None)
else:
return (self.__class__, ({k: v
for k, v in super().items()}, ), None,
None, None, None)

def __eq__(self, other):
if isinstance(other, ConfigDict):
Expand Down
Loading