-
Notifications
You must be signed in to change notification settings - Fork 525
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
Disallow calling del_component
with ComponentData arguments
#3440
base: main
Are you sure you want to change the base?
Changes from all commits
45691f7
f382c1e
4dcfc65
871c99d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
from pyomo.common.timing import ConstructionTimer | ||
from pyomo.core.base.component import ( | ||
Component, | ||
ComponentData, | ||
ActiveComponentData, | ||
ModelComponentFactory, | ||
) | ||
|
@@ -1139,6 +1140,14 @@ def del_component(self, name_or_object): | |
# return | ||
|
||
name = obj.local_name | ||
if isinstance(obj, ComponentData) and not isinstance(obj, Component): | ||
raise ValueError( | ||
"Argument '%s' to del_component is a ComponentData object. Please " | ||
"use the Python 'del' function to delete members of indexed " | ||
"Pyomo objects. The del_component function can only be used to " | ||
"delete IndexedComponents and ScalarComponents." % name | ||
) | ||
|
||
Comment on lines
+1143
to
+1150
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't do what you think it does: line 1133 (
|
||
if name in self._Block_reserved_words: | ||
raise ValueError( | ||
"Attempting to delete a reserved block component:\n\t%s" % (obj.name,) | ||
|
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.
This is unnecessary (it implicitly happens when you reassign
obj
in the for loop in the next line)