Closed huguesdevimeux closed 10 months ago
A few comments on that, but I'm not familiar (yet :) ) with the library, so it may not be as accurate. For the few things I know, here is my take :
For what you have described, I understand that Config
would do exactly what class parameters are for. Can you clarify in what extent it would differ ?
Also, I think we are mixing up two things there, that can lead to a flawed design.
Config options have type annotations that can be used to create control elements for a (web)app.
I don't think this should be mixed up with the user public API, but rather encapsulated in a Mixin/Abstract class WebComponent
(or other name). It would provide the necessary interface for the web app to get the menus/others inputs requests.
It's just a quite hot take. Let me know what you think.
For what you have described, I understand that
Config
would do exactly what class parameters are for. Can you clarify in what extent it would differ ?
That's right, the goal of this mechanism is to enable creating objects from descriptors ("objects representing a JSON configuration"). Naturally, the described properties will be used as arguments upon creation of the described object and therefore there is a correspondence between the descriptor's properties with the described's properties. Hence the first requirement of straightforward maintainability.
but rather encapsulated in a Mixin/Abstract class WebComponent
This is not a planned feature within DiMCAT. What is meant is that configuration options' types (and value constraints) need to be discoverable for other tools, and one example would be a webapp that wants to create appropriate control elements from them.
Thanks for the fruitful discussion, @huguesdevimeux. Here's a sketch (adapted from the minimal working example mwe.py
) of the current tentative design, that we are going to try and improve using marshmallow. The current design stays with the initial idea that every object has a .config
field, only that here it's not a simple dictionary but the respective Config
object.
I think that's a good design, but we will have to be careful - and that can actually be quite a big issue - to unexpected behaviour with mutable variables within Config
.
For example, if a same reference to a Config
object is used multiple times in the code, if a mutable value is modified in the object, it would modify it for every object instantiated with the same reference Config
object. It can lead to some annoying side effects.
That's why I think config should be a private attribute, and accessed only with a getter that would return a deep copy each time. Performance-wise, it's not good, but the end-user is not supposed to use repeatedly. Or, we could make Config immutable, but that's ... not really possible with python.
Let me know what you think.
That's why at one point I was using frozen dataclasses for configs but these come with other disadvantages. Apart from the fact that with dataclasses it is not straightforward to define partial configs, e.g. to find all configs that match two particular settings (and pass that info around).
Anyway, the idea would be for you to transform the mwe in a way that it works with marshmallow. I don't know how easy this transformation will be in this setup; it could be that development will be more straightforward using mock objects.
I see, that's pretty neat !
e.g. to find all configs that match two particular settings (and pass that info around)
Wait, is that a planned feature as well ? That's very nice, but maybe it changes some things implementation-wise. Do you mind to elaborate ?
Anyway, the idea would be for you to transform the mwe in a way that it works with marshmallow. I don't know how easy this transformation will be in this setup; it could be that development will be more straightforward using mock objects.
I will do that asap - not this week, though.
Wait, is that a planned feature as well ? That's very nice, but maybe it changes some things implementation-wise. Do you mind to elaborate ?
It's point 6. in the OP.
Following an exchange by e-mail with @johentsch :
Edit: Configs should be hashable.