ConfigDict¶
- class mmengine.config.ConfigDict(*args, **kwargs)[source]¶
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)[source]¶
If class attribute
lazy
is False, the LazyObject will be built and returned.- Parameters:
value (Any) – The value to be built.
- Returns:
The built value.
- Return type:
Any
- copy() a shallow copy of D ¶
- get(key, default=None)[source]¶
Get the value of the key. If class attribute
lazy
is True, the LazyObject will be built and returned.- Parameters:
key (str) – The key.
default (any, optional) – The default value. Defaults to None.
- Returns:
The value of the key.
- Return type:
Any
- items()[source]¶
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)[source]¶
Merge another dictionary into current dictionary.
- Parameters:
other (dict) – Another dictionary.
- pop(key, default=None)[source]¶
Pop the value of the key. If class attribute
lazy
is True, the LazyObject will be built and returned.- Parameters:
key (str) – The key.
default (any, optional) – The default value. Defaults to None.
- Returns:
The value of the key.
- Return type:
Any
- to_dict()[source]¶
Convert the ConfigDict to a normal dictionary recursively, and convert the
LazyObject
orLazyAttr
to string.