-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Instantiate structured configs (#502)
* to_container: instantiate_structured_configs flag * add a failing test * fix typo * fix bug * another bugfix * solved an issue * add type assert * updates * test instantiation of subclass of Dict[str, User] * test instantiate_structured_configs-Str2UserWithField * fix bug with allow_objects flag * add comment * remove dependence on ref_type; use object_type * use keyword args in call to _instantiate_structured_config_impl * refactor for clearer control flow * move method _instantiate_structured_config_impl * fix lint/mypy errors * remove unnecessary allow_objects flag * rename parameter 'instantiate_structured_configs' -> 'instantiate' * create OmegaConf.to_object alias for OmegaConf.to_container * One use case per test * coverage: use to_object(cfg) instead of to_container(object, instantiate=True) * rename tests: to_object instead of to_container * tests: user str key instead of int key * tests: change 'assert ... is MISSING' -> 'assert ... == MISSING' * add tests for object nested inside object * one use case per tests: dict subclass * test_structured_config.py: consolidate instantiate=True tests * finish rebase against master * Move TestInstantiateStructuredConfigs to test_to_container.py * Create get_structured_config_field_names function * OmegaConf.to_object: resolve=True by default * change _instantiate_structured_config_impl fn signature * separate positive and negative test cases * switch order of cases in _instantiate_structured_config_impl * switch order of cases in _instantiate_structured_config_impl * regroup tests for extracting structured config info * Undo a stylistic change to tests/structured_conf/test_structured_config.py This change would be best left for another PR. * add failing tests for throw if MISSING * Update omegaconf/_utils.py Co-authored-by: Olivier Delalleau <[email protected]> * fix mypy and flake8 issues * implement MissingMandatoryValue in case of MISSING param to dataclass instance * update a test to reflect new behavior r.e. MISSING * use correct-typed value in test of KeyValidationError * modify to_object docstring * use a set for _instantiate_structured_config_impl field names * remove redundant call to set() * refactor TestInstantiateStructuredConfigs - parametrize the `module` fixture directly - reorder tests for increased consistency (test non-missing case before missing case) * TestInstantiateStructuredConfigs: remove redundant isinstance assertions Testing `isinstance(a, A)` is redundant if we are testing `type(a) is A` on the next line. * Use setattr(instance, k, v) when structured config has extra fields * add news fragment * refactoring: rename variables * Test error message for MissingMandatoryValue * Formatting: delete whitespace * include $OBJECT_TYPE in MissingMandatoryValue err msg * change _instantiate_structured_config_impl to an instance method * simplify `retdict` & `retstruct` to `ret` * rename `conf` -> `self` in _instantiate_structured_config_impl * remove `resolve` arg from `to_object` * Docs example for SCMode.INSTANTIATE * docs: OmegaConf.to_object example * Docs minor edit * updates to to_object docs * Revert test_structured_config.py (remove redundant test) * dict subclass: DictConfig items become instance attributes * docs: use `show` instead of `print`/`assert` * minor doc fix Co-authored-by: Olivier Delalleau <[email protected]> * docs: Improve introduction to `to_object` method * docs: Remove explanation r.e. equivalent OmegaConf.to_container calls * docs: clarification on ducktyping Co-authored-by: Omry Yadan <[email protected]> * to_container docs: explicitly document the new SCMode.INSTANTIATE member * update `to_object` docstring * docs: fix typos Co-authored-by: Olivier Delalleau <[email protected]> * empty commit (to trigger CI workflow) * refactor test_SCMode * lowercase test fn name (test_SCMode -> test_scmode) * StructuredConfigs have resolve=True and enum_to_str=False * minor: revert whitespace addition * Edit to news/472.feature Co-authored-by: Omry Yadan <[email protected]> * don't mention enum_to_str * formatting and title for structured_config_mode docs * remove TODO comment * fix comment formatting * move `import get_structured_config_field_names` to top of file * one last formatting adjustment Co-authored-by: Olivier Delalleau <[email protected]> Co-authored-by: Omry Yadan <[email protected]>
- Loading branch information
1 parent
a03f681
commit 0249455
Showing
12 changed files
with
456 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Add the OmegaConf.to_object method, which converts Structured Configs to native instances of the underlying `@dataclass` or `@attr.s` class. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.