Giter Site home page Giter Site logo

odelalleau / omegaconf Goto Github PK

View Code? Open in Web Editor NEW

This project forked from omry/omegaconf

0.0 0.0 0.0 7.47 MB

Flexible Python configuration system. The last one you will ever need.

License: BSD 3-Clause "New" or "Revised" License

Python 99.22% ANTLR 0.76% Gherkin 0.01%

omegaconf's People

Contributors

1heart avatar alexvicegrab avatar anthonytec2 avatar arisliang avatar ericcousineau-tri avatar felixmin avatar glef1x avatar gwenzek avatar hadim avatar jasha10 avatar jeffknaide avatar jgehring avatar jieru-hu avatar kfollesdal avatar lgtm-migrator avatar maresb avatar matteovoges avatar odelalleau avatar ohad31415 avatar omry avatar pereman2 avatar pixelb avatar shagunsodhani avatar shuki-hpcnt avatar simonstjg avatar sugatoray avatar swist avatar tk-woven avatar tmke8 avatar willfrey avatar

Watchers

 avatar

omegaconf's Issues

Deprecate `OmegaConf.is_none()

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.