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
Added capability for IVCs to be instantiated with a list of variables #3197
Conversation
@@ -39,6 +39,16 @@ def __init__(self, name=None, val=1.0, **kwargs): | |||
if isinstance(name, str): | |||
super().add_output(name, val, **kwargs) | |||
|
|||
elif isinstance(name, (list, tuple)): | |||
for tup in name: | |||
if len(tup) == 2: |
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.
You might want to verify here that tup is actually a tuple, or at least not a string. Otherwise in cases where the user gives you a list/tuple of strings, you'll get weird error messages. I could see a user just providing a list of strings and assuming those variables would all have default values.
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.
Good call, I've modified this and pushed up!
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.
I think the docstring for name
needs to be updated for these new possibilities...
Also maybe some kind of error checking on the tup
values (i.e. tup[0] must be a string, tup[2] must be a dict?)?
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.
Thanks Steve, I've updated the docstring and added type checking!
@@ -39,6 +39,16 @@ def __init__(self, name=None, val=1.0, **kwargs): | |||
if isinstance(name, str): | |||
super().add_output(name, val, **kwargs) | |||
|
|||
elif isinstance(name, (list, tuple)): | |||
for tup in name: | |||
if len(tup) == 2: |
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.
I think the docstring for name
needs to be updated for these new possibilities...
Also maybe some kind of error checking on the tup
values (i.e. tup[0] must be a string, tup[2] must be a dict?)?
Thanks for the ping, @swryan, I just fixed the pep issues |
Summary
There's an error message for IndepVarComp that says you can use an iterable at instantiation, but I don't think the code was there anymore.
I added the option to do that here and two tests accordingly.
Shout-out to @crecine for trying this and saying "hey should this work?"
Related Issues
Backwards incompatibilities
None
New Dependencies
None