-
Notifications
You must be signed in to change notification settings - Fork 15
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
ENH: Add dunder accessors to Pydantic RootModels #767
Conversation
from fmu.dataio._model.global_configuration import Stratigraphy, StratigraphyElement | ||
|
||
# -------------------------------------------------------------------------------------- | ||
# Parameters |
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.
Typo. I guess this heading should be Stratigraphy
# Parameters | ||
# -------------------------------------------------------------------------------------- | ||
|
||
testset_stratigraphy = Stratigraphy( |
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.
You could consider implementing this as a fixture in pytest. Then you can take the fixture as input to your test. Example here:
@pytest.fixture(name="direct_creation", scope="function") |
More info here https://www.geeksforgeeks.org/fixtures-in-pytest/
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.
Agree, this would be nice to have as a fixture
You probably need the prefix "ENH" in the title of the PR as well since the squash merge will use the PR title as the commit message. |
I see is also this class fmu-dataio/src/fmu/dataio/_model/data.py Line 621 in b30c170
|
Nice work 👍 Added a few comments. Note the mypy check that is failing. @mferrera should probably also take a look at this. |
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 looks good. I think fixing the type annotations and using fixtures will make this good-to-go. There might be some more complaints from mypy; we had this experience with @slangeveld implementing __iter__
on another class if I recall
# Parameters | ||
# -------------------------------------------------------------------------------------- | ||
|
||
testset_stratigraphy = Stratigraphy( |
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.
Agree, this would be nice to have as a fixture
# Parameters | ||
# -------------------------------------------------------------------------------------- | ||
|
||
testset_params = Parameters( |
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.
Fixtures often go into a conftest.py
if they are used in multiple places. There is always one in the root of the test structure, but we can also put them into nested directories. It will check the ones in nested directories first before walking down to the test root.
In this case, since the fixtures are so specific to these tests, it's best to just define them within the same test module file, not in a conftest.py
src/fmu/dataio/_model/fields.py
Outdated
def __iter__(self) -> Dict[str, Union[Parameters, int, float, str]]: | ||
return iter(self.root) |
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 type annotation is not quite right. iter()
creates an iterator over the Dict[str, Union[Parameters, int, float, str]]
so it won't return the dict, and by default iterating over the dict iterates over the keys of the dict.
So it should be:
def __iter__(self) -> Dict[str, Union[Parameters, int, float, str]]: | |
return iter(self.root) | |
def __iter__(self) -> Iterator[str]: | |
return iter(self.root) |
because we have the keys as strings: Dict[str, ...]
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.
Thanks, I was a little bit too quick ...
def __iter__(self) -> Dict[str, StratigraphyElement]: | ||
return iter(self.root) |
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 be the same thing here with returning an Iterator
. However, we may need to see if mypy likes this or not 😄
Thanks for your comments, guys :-) |
3aeaeec
to
ce22180
Compare
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.
🚀
Remember to squash merge or rebase into a single commit before merging
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.
Looks good 😄
ce22180
to
f66fa73
Compare
Resolves #687