Defer processing ConfigValue/ConfigList default value until first use#3394
Merged
jsiirola merged 15 commits intoPyomo:mainfrom Nov 1, 2024
Merged
Defer processing ConfigValue/ConfigList default value until first use#3394jsiirola merged 15 commits intoPyomo:mainfrom
ConfigValue/ConfigList default value until first use#3394jsiirola merged 15 commits intoPyomo:mainfrom
Conversation
ConfigValue/ConfigList default value until first use
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3394 +/- ##
==========================================
+ Coverage 88.54% 88.59% +0.05%
==========================================
Files 883 883
Lines 100307 100334 +27
==========================================
+ Hits 88813 88889 +76
+ Misses 11494 11445 -49
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
mrmundt
requested changes
Oct 31, 2024
| return fcn | ||
|
|
||
|
|
||
| class UninitializedMixin(object): |
Contributor
There was a problem hiding this comment.
Don't need (object) (we'll never stop having this argument, I know)
|
|
||
| __slots__ = ('_declared', '_implicit_declaration', '_implicit_domain') | ||
| _all_slots = set(__slots__ + ConfigBase.__slots__) | ||
| __slots__ = ('_implicit_domain', '_declared', '_implicit_declaration') |
Member
Author
There was a problem hiding this comment.
Yes. __getstate__ processes all __slots__ except for _implicit_domain in a general manner (_implicit_domain is handled separately). This processing works by skipping the first element in __slots__. See the Note on lines 2607-2608.
| ) | ||
|
|
||
| def test_display_nondata_type(self): | ||
| class NOOP(object): |
| self.assertEqual(mod_copy._visibility, 0) | ||
|
|
||
| def test_template_nondata(self): | ||
| class NOOP(object): |
| self.assertEqual(cfg.get('type').domain_name(), 'int') | ||
|
|
||
| def test_deferred_initialization(self): | ||
| class Accumulator(object): |
mrmundt
approved these changes
Oct 31, 2024
emma58
approved these changes
Oct 31, 2024
Comment on lines
+48
to
+49
| self.assertIs(NOTSET(), NOTSET) | ||
| self.assertIs(NOTSET(), NOTSET()) |
Co-authored-by: Emma Johnson <[email protected]>
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.
Fixes #3244 .
Summary/Motivation:
NOTE: this PR builds on #3382. You can see / review the new content in this PR through this link
It is useful to have
ConfigValueobjects that have complex (read: heavy-weight) domains. For example, it would be convenient for a transformation to take a single configuration field for a (preconfigured)solver. Unfortunately, we would like that domain to be aSolverBaseinstance - and providing a default solver would force that solver to be instantiated when theConfigValue(ConfigDict) was declared.This PR updated the internals to defer passing the
_defaultvalue through_castuntil the first time the_datais accessed / needed.In addition, this cleans up some other issues in the Config classes:
dicts)__slots__declarationsFlagTypeso that instances of those classes can't be constructed (attempts to call the type will return the type and not an instance)Changes proposed in this PR:
Legal Acknowledgement
By contributing to this software project, I have read the contribution guide and agree to the following terms and conditions for my contribution: