Skip to content
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

Improve ConfigData & related #101

Merged
merged 20 commits into from
Jan 27, 2025
Merged

Improve ConfigData & related #101

merged 20 commits into from
Jan 27, 2025

Conversation

DropD
Copy link
Collaborator

@DropD DropD commented Jan 21, 2025

  • Add Tests
  • Rewrite _NamedBaseModel to allow alternative creation of models with intuitive kwargs from python
  • Make .type and .src non-optional in ConfigBaseDataSpecs
  • Change ConfigBaseDataSpecse.type type to an enum (replaces string-based validator while improving legibility)
  • In combination no need to add a "canonical" version.

src/sirocco/parsing/_yaml_data_models.py Outdated Show resolved Hide resolved
case _:
msg = f"{cls.__name__} requires name to be a str (got {key})."
raise TypeError(msg)
return data
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this make sense to be a classmethod? I typically see classmethods used only for creating an instance the class (so this function would dict -> _NamedBaseModel). Here we create a dict object. Don't you think a staticmethod is more transparently communicating that not an instance of the same class is created?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My reasons:

  • Model validators in pydantic docs are classmethods (this is only a separate method to allow additional usage).
  • It allows access to cls.__name__, which will report the name of the subclass. This is more helpful and less confusing than always reporting the name of the base class.
  • This class method is not designed to deal with arbitrary dicts. Semantically, it is not intended to have meaning outside this class. Therefore it violates the rule "staticmethod could also be standalone function"
  • If there is value in it being designed for standalone usage, I would prefer to make it a standalone function and design and test it accordingly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually changed the usage in get_plugin_from_named_base_model to use the ConfigBaseTask.extract_merge_name, which should cause errors to report the right class name there as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok good points!

@DropD DropD requested review from leclairm and agoscinski January 22, 2025 11:00
Copy link
Collaborator

@agoscinski agoscinski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just had two minor suggestions . I think they are really marginal so I already approve. Thanks for the work!

src/sirocco/parsing/_yaml_data_models.py Show resolved Hide resolved
src/sirocco/parsing/_yaml_data_models.py Outdated Show resolved Hide resolved
src/sirocco/parsing/_yaml_data_models.py Outdated Show resolved Hide resolved
src/sirocco/parsing/_yaml_data_models.py Show resolved Hide resolved
@DropD DropD merged commit 6051f9c into C2SM:main Jan 27, 2025
3 checks passed
@DropD DropD deleted the improve-config-data branch January 27, 2025 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants