-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Config dict #10
Config dict #10
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10 +/- ##
==========================================
+ Coverage 78.15% 79.01% +0.86%
==========================================
Files 22 23 +1
Lines 1927 2035 +108
==========================================
+ Hits 1506 1608 +102
- Misses 421 427 +6 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm quite happy with the idea of using a mixin. The code is (as usual) well written, simple and clean.
I have a few concerns, mainly regarding the use of type hints:
- As you can see in the checks, the currently used type hints don't work for all Python versions (major changes were added in Python 3.9, some smaller later). I don't know whether we can make it work for all versions.
- In my opinion, type hints are hints - and are usually not enforced.
This is probably not a blocking issue. Unless I am mistaken, we could simply check the types at (de-)serialisation time.
One open question: How would you deserialise an object (i.e. from YAML to a Python object). I couldn't find any references to the Python objects class/module yet and it would also need some kind of from_dict
class function to recover an object.
ifsbench/config_mixin.py
Outdated
|
||
|
||
def _config_from_locals(config: dict[str, Any]) -> None: | ||
print(f'from locals: config={config}, type={type(config)}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment for later (I now that this is a draft). Most output in ifsbench
is done via the debug/info/warning/....
functions in ifsbench.logging
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was just a debug output I forgot. Removed now
ifsbench/config_mixin.py
Outdated
def update_config(self, field: str, value: CONF) -> None: | ||
if field not in self._config: | ||
raise ValueError(f'{field} not part of config {self._config}, not setting') | ||
if type(value) != type(self._config[field]): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type comparisons might be dangerous here, if we work with subclasses (for example if a class stores multiple DataHandler
objects in a list).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed to isinstance
ifsbench/config_mixin.py
Outdated
config: dictionary containing parameter names and their values | ||
""" | ||
|
||
_config = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should probably be given a less generic name like _mixin_config
. Otherwise this might clash with classes that have their own _config
attribute (which is probably not that rare).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
@uhager First of all, many thanks for looking into this, and even though it's still a draft, I think this is a very promising start for a complex design issue. I've not looked through this in detail, but the initial discussion is already super interesting and valuable. So, thanks for your initiative! 🙏 @uhager and @johannesbulin I agree on both accounts that the Mixin approach is great, and that using type-info for the necessary introspection are very neatly done. On @johannesbulin point about type-safety and automated checking, I would like to point out that there is also the option to use Pydantic: https://docs.pydantic.dev/latest/ And lastly, I'm open to either solution, but as type-safety and introspection were raise, I thought I'd throw out some pointers. |
I think that should be a separate function / class with implementations for yaml, json, or whatever we want to support. That function will parse the yaml, create the config dicts, and call the build functions in the classes that need to be created |
Fine with the separate function to start the whole (de-)serialising process. Still, if you have a class like this
you would have |
Looked into that, looks promising. I have never used pydantic, so to see what's possible I made a prototype implementation: #13 That approach is a lot cleaner than this one, but may end up less flexible. So far it's looking good though. |
No description provided.