odelalleau / omegaconf Goto Github PK
View Code? Open in Web Editor NEWThis project forked from omry/omegaconf
Flexible Python configuration system. The last one you will ever need.
License: BSD 3-Clause "New" or "Revised" License
This project forked from omry/omegaconf
Flexible Python configuration system. The last one you will ever need.
License: BSD 3-Clause "New" or "Revised" License
PROBLEM
With the change to OmegaConf.is_missing()
in omry#545, the current behavior of OmegaConf.is_none()
in OmegaConf 2.0 can be confusing (because it resolves interpolations, while OmegaConf.is_missing()
doesn't).
In addition, OmegaConf.is_none()
has potentially non-intuitive behavior in situations where the key can't be resolved (see below for details).
SOLUTION
OmegaConf.is_none()
is being partially deprecated in OmegaConf 2.1 to have a simpler and more explicit behavior.
MIGRATION INSTRUCTIONS
Scenario 1 -- Your code is checking a specific key:
OmegaConf.is_none(cfg, "foo")
OmegaConf.is_none(cfg, key)
It is recommended to change these to:
cfg.foo is None
cfg[key] is None
Note however that when using this new syntax, an exception may be raised when accessing the key, while OmegaConf.is_none()
used to silence such exceptions. If you want to keep the exact (but possibly unintuitive) behavior from before, you can implement your own is_none()
function as follows:
def is_none(obj: Container, key: Union[int, DictKeyType]) -> bool:
try:
return obj[key] is None
except ConfigKeyError:
return True # `True` if the key does not exist in the config
except (InterpolationResolutionError, MissingMandatoryValue):
return False # `False` if it is either missing ("???") or an invalid interpolation
Scenario 2 -- Your code is not providing a key:
OmegaConf.is_none(obj)
It is recommended to change this check into:
OmegaConf.is_none(obj, resolve=True)
Note however that if obj
is an interpolated node, an exception may be raised during interpolation resolution, while the old OmegaConf.is_none(obj)
would silence it and return False
. If you want to keep this behavior, then you should use:
OmegaConf.is_none(obj, resolve=True, throw_on_resolution_failure=False)
Additional context
See discussion in omry#545 (comment)
Dev note: at the same time, the internal Node._is_none()
can be modified to not resolve interpolations.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.