Commit e48be57c authored by Paul McCarthy's avatar Paul McCarthy 🚵
Browse files

RF/ENH: Wrapper outputs are now accessible as attributes in addition to dict

items (where possible). Result standard output renamed from "output" to
parent 30ed9039
......@@ -545,20 +545,44 @@ class _FileOrThing(object):
items, with the argument name as key, and the output object (the
"thing") as value.
Where possible (i.e. for outputs named with a valid Python
identifier), the outputs are also made accessible as attributes of
The decorated function's actual return value is accessible via the
:meth:`output` property.
:meth:`stdout` property.
def __init__(self, output):
def __init__(self, stdout):
"""Create a ``_Results`` dict.
:arg stdout: Return value of the ecorated function (typically the
standard output of the underlying command).
self.__output = output
self.__stdout = stdout
def __setitem__(self, key, val):
"""Add an item to the dict. The item is also added as an attribute
if possible.
super().__setitem__(key, val)
# try and add as an attribute too,
# but don't bother if the key cannot
# be used as a python identifier
setattr(self, key, val)
except AttributeError:
def output(self):
def stdout(self):
"""Access the return value of the decorated function. """
return self.__output
return self.__stdout
def __init__(self,
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment