Interactive Python environments such as IPython and modern versions of regular (C) Python support auto-completion for object attributes by inspecting the list returned by dir(). Under the hood the built-in function attempts to call __dir__() to see if the object has a custom list of attributes. This PR adds an implementation of a custom __dir__() method for Resource objects that returns the known attributes of the resource as well as the regular methods for resources, allowing for auto-completion as the resource hierarchy is browsed interactively. This is even more effective if the client connects with lazy_load=False, but will work one layer deep without this option.
The implementation here hides both internal methods (i.e. those beginning with _ characters) and also Redfish internal attributes (those beginning with @) in the result set, although these are still accessible directly.
Tests for the new method have been added to tests/test_resource.py.
Note: due to a known bug in the jedi library, modern versions of IPython have problems performing auto-completion on objects that offer custom implementations of __dir__. This bug can be avoided by executing %config IPCompleter.use_jedi = False to disable use of the buggy library.
Interactive Python environments such as IPython and modern versions of regular (C) Python support auto-completion for object attributes by inspecting the list returned by
dir()
. Under the hood the built-in function attempts to call__dir__()
to see if the object has a custom list of attributes. This PR adds an implementation of a custom__dir__()
method forResource
objects that returns the known attributes of the resource as well as the regular methods for resources, allowing for auto-completion as the resource hierarchy is browsed interactively. This is even more effective if the client connects withlazy_load=False
, but will work one layer deep without this option.The implementation here hides both internal methods (i.e. those beginning with
_
characters) and also Redfish internal attributes (those beginning with@
) in the result set, although these are still accessible directly.Tests for the new method have been added to
tests/test_resource.py
.Note: due to a known bug in the
jedi
library, modern versions of IPython have problems performing auto-completion on objects that offer custom implementations of__dir__
. This bug can be avoided by executing%config IPCompleter.use_jedi = False
to disable use of the buggy library.