Parameter names
Parameter names can either be set manually or otherwise they will be derived (autocompleted) by the framework:
from hanna import Configurable, String
class Example(Configurable):
manual = String('custom_name')
derived = String()
Example.manual.name # "custom_name"
Example.derived.name # "derived"
By default the autocomplete of parameter names only works inside class definitions. That is if you set a parameter on an existing class then its name won't be autocompleted:
class Example(Configurable):
pass
Example.test = String()
assert Example.test.name is None
Activating autocomplete of parameter names outside of class definitions
If you want to use this feature you can enable it by installing the corresponding add-on:
from hanna.addons import AutocompleteParameterNames
AutocompleteParameterNames.install()
Note that as a consequence of installing the autocomplete feature the Configurable class will receive a custom metaclass which might lead to metaclass conflicts if you use custom metaclass as well. For details see the doc string of AutocompleteParameterNames
.
We need to re-import the Configurable class because it was replaced by the add-on and then we can use the feature:
from hanna import Configurable # Need to re-import otherwise we use
# the old (non-autocomplete) class.
class Example(Configurable):
pass
Example.test = String()
assert Example.test.name == 'test'
If you want to switch back to default behavior you can uninstall the feature via:
AutocompleteParameterNames.uninstall()
from hanna import Configurable # Re-import again because the class
# has been reset.
Last updated