Dataclass-like types accept the same values whether or not added as a group - #952
Merged
Merged
Conversation
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #952 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 27 27
Lines 8252 8305 +53
=========================================
+ Hits 8252 8305 +53 ☔ View full report in Codecov by Harness. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.



What does this PR do?
A dataclass-like type is added as an argument group when it is the entire type of an
argument (each field becomes its own option, e.g.
--data.number), but as a singletypehint argument when it is part of a larger type (e.g.
Optional[Data],list[Data]). The accepted values differed between these two cases. This PR makes themconsistent and fixes several related issues.
Changed
class_pathof the type itself, e.g.--data='{"class_path": "Data", "init_args": {...}}', instead of failing withGroup 'data' does not accept option 'init_args....'.Fixed
Optional[Data], accepted theclass_pathof a subclass, even though subclasses are disabled for these types bydefault. The error now explains how to enable subclass support.
Optional[Data],list[Data],dict[str, Data]) did not accept a path to a sub-config file even withsub_configs=True, failing with e.g.No module named 'data'. Also, the path of aloaded sub-config was not kept, so
savewithmultifile=Truedid not write it backto its own file.
APP_SUB__DATA='{"p1": 2}', failed withNot a valid subclass of ....Added
shtabcompletion scripts now include the fields of a dataclass-like type that is notadded as a group.
Documentation updated in the
subclasses-disabledandsub-config-filessections; newtests in
test_dataclasses.py,test_paths.py,test_pydantic.py,test_shtab.pyandtest_subcommands.py.Before submitting