To clarify, here is the source code of the function:
def contains(dumpable_object, item_name) -> bool:
"""Returns true if item_name is present in dump string of dumpable_object."""
str_io = io.StringIO()
with redirect_stdout(str_io):
dumpable_object.dump()
return item_name in str_io.getvalue()
There are two code smells here:
Using StringIO and redirect_stdout to get the value of dumpable_object.dump() rather than adding an output stream parameter to dump() or returning a string from it.
Dumping the string and doing a text-based match in the first place seems like the wrong way to approach this. It is used in 4 places to check whether an object is mentioned in (1) the initial state, (2) an action, (3) a positive atom inside a condition, or (4) a negated atom inside a condition. Points (3) and (4) should look directly at the arguments of the atom. Point (2) should forward the call to the components of the action (actually maybe the forwarding should not be done here but that is a separate issue: #62 ). Point (3) should also look at the individual atoms of the state.
To clarify, here is the source code of the function:
There are two code smells here:
StringIO
andredirect_stdout
to get the value ofdumpable_object.dump()
rather than adding an output stream parameter todump()
or returning a string from it.