-
Notifications
You must be signed in to change notification settings - Fork 4
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
Conversation
* finalize ConfigWorkflow canonicalization * improve type hints
case _: | ||
msg = f"{cls.__name__} requires name to be a str (got {key})." | ||
raise TypeError(msg) | ||
return data |
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.
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?
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.
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.
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 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.
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.
ok good points!
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 had two minor suggestions . I think they are really marginal so I already approve. Thanks for the work!
_NamedBaseModel
to allow alternative creation of models with intuitive kwargs from python.type
and.src
non-optional inConfigBaseDataSpecs
ConfigBaseDataSpecse.type
type to an enum (replaces string-based validator while improving legibility)