-
Notifications
You must be signed in to change notification settings - Fork 122
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OmegaConf.to_object
: Instantiate structured configs
#502
Merged
Merged
Changes from all commits
Commits
Show all changes
90 commits
Select commit
Hold shift + click to select a range
15d9abb
to_container: instantiate_structured_configs flag
Jasha10 c4b042a
add a failing test
Jasha10 fe47c89
fix typo
Jasha10 c91be99
fix bug
Jasha10 59ee909
another bugfix
Jasha10 14b75be
solved an issue
Jasha10 3354bad
add type assert
Jasha10 5cb06ed
updates
Jasha10 a3676e3
test instantiation of subclass of Dict[str, User]
Jasha10 c5f5e73
test instantiate_structured_configs-Str2UserWithField
Jasha10 abf8af0
fix bug with allow_objects flag
Jasha10 a54cb98
add comment
Jasha10 5fdd019
remove dependence on ref_type; use object_type
Jasha10 fc49cbd
use keyword args in call to _instantiate_structured_config_impl
Jasha10 64b3ed7
refactor for clearer control flow
Jasha10 41588c1
move method _instantiate_structured_config_impl
Jasha10 653a54e
fix lint/mypy errors
Jasha10 65497ee
remove unnecessary allow_objects flag
Jasha10 1640f8b
rename parameter 'instantiate_structured_configs' -> 'instantiate'
Jasha10 7e52b24
create OmegaConf.to_object alias for OmegaConf.to_container
Jasha10 8dfd397
One use case per test
Jasha10 68b1f74
coverage: use to_object(cfg) instead of to_container(object, instanti…
Jasha10 5b47049
rename tests: to_object instead of to_container
Jasha10 15324e9
tests: user str key instead of int key
Jasha10 375babf
tests: change 'assert ... is MISSING' -> 'assert ... == MISSING'
Jasha10 6422f39
add tests for object nested inside object
Jasha10 ecc05b1
one use case per tests: dict subclass
Jasha10 9d7addc
test_structured_config.py: consolidate instantiate=True tests
Jasha10 7136baa
finish rebase against master
Jasha10 841ac01
Move TestInstantiateStructuredConfigs to test_to_container.py
Jasha10 fa81a4d
Create get_structured_config_field_names function
Jasha10 872850b
OmegaConf.to_object: resolve=True by default
Jasha10 072e8d8
change _instantiate_structured_config_impl fn signature
Jasha10 1953a47
separate positive and negative test cases
Jasha10 91de025
merge updates from master
Jasha10 a4af7f5
switch order of cases in _instantiate_structured_config_impl
Jasha10 efcc93b
switch order of cases in _instantiate_structured_config_impl
Jasha10 f94ecbd
merge
Jasha10 5b51861
regroup tests for extracting structured config info
Jasha10 7e299cf
Merge branch 'master' into instantiate-structured-configs
Jasha10 19de3b4
Undo a stylistic change to tests/structured_conf/test_structured_conf…
Jasha10 84c00ac
add failing tests for throw if MISSING
Jasha10 488a4b3
Update omegaconf/_utils.py
Jasha10 bbbb245
fix mypy and flake8 issues
Jasha10 37e055f
implement MissingMandatoryValue in case of MISSING param to dataclass…
Jasha10 961b9fd
update a test to reflect new behavior r.e. MISSING
Jasha10 7f8addb
use correct-typed value in test of KeyValidationError
Jasha10 a10fa5b
modify to_object docstring
Jasha10 6b014ae
use a set for _instantiate_structured_config_impl field names
Jasha10 4cefc6d
remove redundant call to set()
Jasha10 b2a5ab2
refactor TestInstantiateStructuredConfigs
Jasha10 d28ae5d
TestInstantiateStructuredConfigs: remove redundant isinstance assertions
Jasha10 62f34cf
Use setattr(instance, k, v) when structured config has extra fields
Jasha10 249ac36
add news fragment
Jasha10 0869121
refactoring: rename variables
Jasha10 3a47132
Test error message for MissingMandatoryValue
Jasha10 46aadbe
Formatting: delete whitespace
Jasha10 c581548
include $OBJECT_TYPE in MissingMandatoryValue err msg
Jasha10 2cf460f
change _instantiate_structured_config_impl to an instance method
Jasha10 d6e9749
simplify `retdict` & `retstruct` to `ret`
Jasha10 f16ad22
rename `conf` -> `self` in _instantiate_structured_config_impl
Jasha10 2bf73b0
remove `resolve` arg from `to_object`
Jasha10 eb41a37
Docs example for SCMode.INSTANTIATE
Jasha10 30550bf
docs: OmegaConf.to_object example
Jasha10 0611c93
Docs minor edit
Jasha10 32f6c68
updates to to_object docs
Jasha10 1019df6
Revert test_structured_config.py (remove redundant test)
Jasha10 3fef7f0
dict subclass: DictConfig items become instance attributes
Jasha10 0019bca
Merge branch 'master' into instantiate-structured-configs
Jasha10 15a03ea
docs: use `show` instead of `print`/`assert`
Jasha10 f3171f2
minor doc fix
Jasha10 80284f4
docs: Improve introduction to `to_object` method
Jasha10 8f17b9a
docs: Remove explanation r.e. equivalent OmegaConf.to_container calls
Jasha10 e1e034a
docs: clarification on ducktyping
Jasha10 5045503
Merge branch 'master' into instantiate-structured-configs
Jasha10 29323a4
to_container docs: explicitly document the new SCMode.INSTANTIATE member
Jasha10 fe5df1d
update `to_object` docstring
Jasha10 a9a05ee
docs: fix typos
Jasha10 db09880
empty commit (to trigger CI workflow)
Jasha10 a17a11f
refactor test_SCMode
Jasha10 29a526b
lowercase test fn name (test_SCMode -> test_scmode)
Jasha10 c672c10
StructuredConfigs have resolve=True and enum_to_str=False
Jasha10 672b180
minor: revert whitespace addition
Jasha10 8beb52a
Edit to news/472.feature
Jasha10 4787e8d
don't mention enum_to_str
Jasha10 c1d13f8
formatting and title for structured_config_mode docs
Jasha10 bc2f610
remove TODO comment
Jasha10 f1a4270
fix comment formatting
Jasha10 b51d33f
move `import get_structured_config_field_names` to top of file
Jasha10 d12701e
one last formatting adjustment
Jasha10 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@omry calling
get_node()
followed by_dereference_node()
is a somewhat common operation and it's a bit annoying right now with the mypy asserts.Would it make sense to add a
get_dereferenced_node()
function that would return aNode
(not optional) to streamline such code?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would make sense to me.
I'll do it in another PR :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First step is here: #668