Closed kalekundert closed 3 years ago
Having given this some more thought, I don't think it makes sense to provide a cast function for values set in python. The idea is that attribute assignment should work pretty much like normal, so concepts like cast
and pick
that make sense for parameters loaded from various configs don't make sense for parameters set in python. Note that I am still planning to add a callback for when a parameter gets loaded/set, see #4.
appcli.param(cast=...)
only applies to values that are loaded from a config. It's not used for default values or values set directly in python. This definitely has its purpose—values from different config sources may need to be normalized differently. But it would also be good to have a way to treat all values in a consistent way, similar to@property
.I can think of two ways to do this. It might be good to support both, since they each have situations where they'd work well:
decorator:
on_get
/getter
callback (goes withon_set
/setter
callback discussed in #4):on_get
callback is also unique from thecast
callback in that it would provide the object itself as an argument.It might also be good to allow a cast function to be specified specifically for values set directly in python. Here's one way to do it, although it feels a bit hacky.
__config__
includes aPythonConfig/SetAttrConfig/ApiConfig
instance.PythonConfig.load()
would set a flag inget_meta(obj)
indicating that values can be set.PythonConfig
instance.PythonConfig
wouldn't make any sense, would need a way to avoid that.