Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/release_notes/pending_release.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ Fixes
Documentation

* Add missing reference to v0.13.0 change notes.

* Add an example for overriding get_default_config
21 changes: 19 additions & 2 deletions python/smqtk/utils/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,27 @@ def get_default_config(cls):
turning those argument names into configuration dictionary keys. If any
of those arguments have defaults, we will add those values into the
configuration dictionary appropriately. The dictionary returned should
only contain JSON compliant value types.
only contain JSON compliant value types. If the default arguments are
not JSON compliant then the function should be overriden to convert
the convert the default to a JSON compliant stand in.

It is not be guaranteed that the configuration dictionary returned
from this method is valid for construction of an instance of this class.
>>> import math
>>> class NonCompliantDefault(Configurable):
Comment thread
Purg marked this conversation as resolved.
... def __init__(self, power_func=math.pow):
... self.power_func=power_func
... @classmethod
... def get_default_config(cls):
... default = super(NonCompliantDefault, cls).get_default_config()
... default['power_func'] = {'module': 'math',
... 'attribute': 'pow'}
... return default
>>> NonCompliantDefault.get_default_config() ==
... {'power_func': {'module': 'math', 'attribute': 'pow'}}
Comment on lines +79 to +80
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing doc-test: requires a slash at the end for the line continuation.

Suggested change
>>> NonCompliantDefault.get_default_config() ==
... {'power_func': {'module': 'math', 'attribute': 'pow'}}
>>> NonCompliantDefault.get_default_config() == \
... {'power_func': {'module': 'math', 'attribute': 'pow'}}

>>> import json
>>> json.dumps(NonCompliantDefault.get_default_config()) ==
... {"power_func": {"module": "math", "attribute": "pow"}}
Comment on lines +82 to +83
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Failing doc-test: requires a slash at the end for the line continuation.

Suggested change
>>> json.dumps(NonCompliantDefault.get_default_config()) ==
... {"power_func": {"module": "math", "attribute": "pow"}}
>>> json.dumps(NonCompliantDefault.get_default_config()) == \
... {"power_func": {"module": "math", "attribute": "pow"}}


:return: Default configuration dictionary for the class.
:rtype: dict
Expand Down Expand Up @@ -106,7 +123,7 @@ def from_config(cls, config_dict, merge_default=True):

This base method is adequate without modification when a class's
constructor argument types are JSON-compliant. If one or more are not,
however, this method then needs to be overridden in order to convert
this method then needs to be overridden in order to convert
from a JSON-compliant stand-in into the more complex object the
constructor requires. It is recommended that when complex types *are*
used they also inherit from the :class:`Configurable` in order to
Expand Down