You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
An historical decision was to make __getitem__ and __getattr__ return None if a the input key is not found.
This is inconsistent with the behavior of plain dict and regular Python objects.
Fixing this is a breaking change, users depending on it will need small code changes.
Note:
DictConfig put into struct mode is already behaving in the new way (raising exceptions).
This change should not affect most Hydra users because Hydra puts the cfg object into struct mode by default.
The text was updated successfully, but these errors were encountered:
omry
changed the title
DictConfig __getitem__ and __getattr__ are inconsistent with plain dict
DictConfig __getitem__ and __getattr__ are inconsistent with plain dict and objects
Feb 5, 2021
omry
changed the title
DictConfig __getitem__ and __getattr__ are inconsistent with plain dict and objects
OmegaConf 2.1: changes in DictConfig __getitem__ and __getattr__
Feb 5, 2021
An historical decision was to make
__getitem__
and__getattr__
return None if a the input key is not found.This is inconsistent with the behavior of plain dict and regular Python objects.
Fixing this is a breaking change, users depending on it will need small code changes.
Accessing a non existing attribute
In general,
Can be replaced with:
Depending on the type annotation of cfg, one may be more appropriate than the other, but both will work.
Checking if an attribute exists
If the context of your usage is is existence check, you can also use:
And
Will have to be replaced with
Note that is cfg is ducktyped as a type, you can use hasattr just like you would on an real instance of Config:
Note:
DictConfig put into struct mode is already behaving in the new way (raising exceptions).
This change should not affect most Hydra users because Hydra puts the cfg object into struct mode by default.
The text was updated successfully, but these errors were encountered: