Open PetrochukM opened 4 years ago
We could also update the name to configs
. The idea of "defaults" is based on overwriting arguments, which isn't entirely how this library is intended to be used.
We could also... instead of having a cryptic function like add_config
that adds another level of abstraction. We could do something like:
import defaults
function.set_defaults(parameter=0)
Object.__init__.set_defaults(parameter='')
Or
import defaults
defaults.set_defaults(function, parameter=0)
defaults.set_defaults(Object.__init__, parameter='')
Or
import defaults
defaults.set_defaults({
function: {
parameter: 0
},
Object.__init__: {
parameter: ''
},
})
Or
import defaults
defaults.set_defaults(
(function, dict(parameter=0)),
(Object.__init__, dict(parameter='')),
)
We could also... maybe... use a generic type to add type checking for set_defaults
.
Or it could be named options
, similar to this: https://docs.streamlit.io/en/stable/api.html#placeholders-help-and-options
Add this quote to the documentation:
https://blog.codinghorror.com/the-power-of-defaults/
Rename this package to
Defaults
, it makes more sense thanHParams
.Example API:
This module is also redundant, the primary interface is via a dotted string path. The dotted string path is then parsed, imported, and hashed. Instead of resolving a string path, we could just accept a function object. The function object is guaranteed to exist, and we can check if it has a configurable wrapper.
We should still use
_get_function_signature
so that the configuration is exportable and importable into another process. We can remove_lazy_resolution
because the import responsibility is on the owner.With regard to external libraries, like
_BatchNorm
andBatchNorm1d
, the issue will continue to persist. At the end of the day, there are two references to the same function. If one of the references is decorated and the other is not, that will cause all kinds of issues. For example, it'll cause issues with the trace. It'll also cause issues with__qualname__
. The proper solution is to create a subclass withBatchNorm1d
that has a separate__init__
with a separate set ofkwargs
.The idea of decorating external libraries is interesting. At the end of the day, the goal of this library is to help configure a bunch of code. Instead of having an external configuration object that is passed through the entire code base, we just directly inject the parameters that we'd like to use.