Making add dataclass options public#60
Closed
martinResearch wants to merge 2 commits intomivade:mainfrom
martinResearch:making_add_dataclass_options_public
Closed
Making add dataclass options public#60martinResearch wants to merge 2 commits intomivade:mainfrom martinResearch:making_add_dataclass_options_public
martinResearch wants to merge 2 commits intomivade:mainfrom
martinResearch:making_add_dataclass_options_public
Conversation
jcal-15
reviewed
Dec 10, 2024
| kwargs["required"] = True | ||
| else: | ||
| kwargs["default"] = MISSING | ||
| kwargs["default"] = field.default |
Contributor
There was a problem hiding this comment.
We need to keep the default as MISSING so that the dataclass's initialization handles the default value. This is needed so default_factory can work correctly.
Also, doing it this way makes the initialization consistent with initializing the dataclass outside of the argparse_dataclass package
jcal-15
reviewed
Dec 10, 2024
Comment on lines
+64
to
+67
| params = argpument_parser.parse_args([]) | ||
| print(params) | ||
| self.assertEqual(42, params.x) | ||
| self.assertEqual(False, params.y) |
Contributor
There was a problem hiding this comment.
parse_args returns a namespace object not a Opt so it is not expected to have the defaults set.
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.
draft PR to solve #58
I wrote this before realizing there was another PR to fix the same issue here
Note that I had to use
kwargs["default"] = field.defaultfor the test to pass. I did not read the code in enough detail to have confidence that it is the right fix.