ConfigDict¶
- class mmengine.config.ConfigDict(*args, **kwargs)[源代码]¶
A dictionary for config which has the same interface as python’s built- in dictionary and can be used as a normal dictionary.
The Config class would transform the nested fields (dictionary-like fields) in config file into
ConfigDict
.If the class attribute
lazy
isFalse
, users will get the object built byLazyObject
orLazyAttr
, otherwise users will get theLazyObject
orLazyAttr
itself.The
lazy
should be set toTrue
to avoid building the imported object during configuration parsing, and it should be set to False outside the Config to ensure that users do not experience theLazyObject
.- build_lazy(value)[源代码]¶
If class attribute
lazy
is False, the LazyObject will be built and returned.- 参数:
value (Any) – The value to be built.
- 返回:
The built value.
- 返回类型:
Any
- copy() a shallow copy of D ¶
- get(key, default=None)[源代码]¶
Get the value of the key. If class attribute
lazy
is True, the LazyObject will be built and returned.- 参数:
key (str) – The key.
default (any, optional) – The default value. Defaults to None.
- 返回:
The value of the key.
- 返回类型:
Any
- items()[源代码]¶
Yield the keys and values of the dictionary.
If class attribute
lazy
is False, the value ofLazyObject
orLazyAttr
will be built and returned.
- merge(other)[源代码]¶
Merge another dictionary into current dictionary.
- 参数:
other (dict) – Another dictionary.
- pop(key, default=None)[源代码]¶
Pop the value of the key. If class attribute
lazy
is True, the LazyObject will be built and returned.- 参数:
key (str) – The key.
default (any, optional) – The default value. Defaults to None.
- 返回:
The value of the key.
- 返回类型:
Any
- to_dict()[源代码]¶
Convert the ConfigDict to a normal dictionary recursively, and convert the
LazyObject
orLazyAttr
to string.