@@ -1132,25 +1132,27 @@ def del_component(self, name_or_object):
11321132 if isinstance (name_or_object , str ):
11331133 if name_or_object in self ._decl :
11341134 obj = self ._decl_order [self ._decl [name_or_object ]][0 ]
1135+ else :
1136+ # Maintaining current behavior, but perhaps this should raise an
1137+ # exception?
1138+ return
11351139 else :
11361140 try :
11371141 obj = name_or_object .parent_component ()
1138- if obj is not name_or_object :
1139- raise ValueError (
1140- "Argument '%s' to del_component is a ComponentData object. "
1141- "Please use the Python 'del' function to delete members of "
1142- "indexed Pyomo components. The del_component function can "
1143- "only be used to delete IndexedComponents and "
1144- "ScalarComponents." % name_or_object .local_name
1145- )
1146- if obj .parent_block () is not self :
1147- obj = None
11481142 except AttributeError :
1149- pass
1150- if obj is None :
1151- # Maintaining current behavior, but perhaps this should raise an
1152- # exception?
1153- return
1143+ # Maintaining current behavior, but perhaps this should raise an
1144+ # exception?
1145+ return
1146+ if obj is not name_or_object :
1147+ raise ValueError (
1148+ "Argument '%s' to del_component is a ComponentData object. "
1149+ "Please use the Python 'del' function to delete members of "
1150+ "indexed Pyomo components. The del_component function can "
1151+ "only be used to delete IndexedComponents and "
1152+ "ScalarComponents." % name_or_object .local_name
1153+ )
1154+ if obj .parent_block () is not self :
1155+ return
11541156
11551157 name = obj .local_name
11561158
0 commit comments