-
Notifications
You must be signed in to change notification settings - Fork 41
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
make Metadata a dataclass #109
Conversation
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 for the contribution and detailed explanation @edsaac - I agree that as implemented the Metadata
class does not follow best practices.
This relates to #75, and is a good solution I think. Will let @thodson-usgs weigh in too as he opened #75 and likely has some thoughts on the Metadata
class.
dataretrieval/utils.py
Outdated
|
||
if __name__ == "__main__": | ||
pass |
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.
Do we need this at the end of the script? We don't have any handling for direct calls of any other other .py
files.
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.
Not really, that idiom is not really necessary unless the file was run as a script.
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 works for me but @thodson-usgs it'd be great to get your approval too before we merge.
I agree that existing implementation was poor. That said, I'm not sure changing to a dataclass really fixes anything. It may be better to use an init function here to abstract how the Metadata is initialized. Something like |
I agree, making it a dataclass just removes those class variables that are initialized to |
Thanks @edsaac, |
Currently, the Metadata class has no
__init__
function but only class variables.I think these are not meant to be class variables but instance variables, as different data requests will return different metadata. Check an example of the difference in https://docs.python.org/3/tutorial/classes.html#class-and-instance-variables. Only
utils.set_metadata
creates Metadata objects and assigns values to the instance object variables, without ever modifying the defaultNone
of the class variables.nwis._set_metadata
behaves similarly in that it only modify objects but never the class itself.Making the Metadata a dataclass helps with making those (url, site_info, etc) instance attributes, without the need to write a long
__init__
function. Dataclasses have been part of the standard library since 3.7 so there should not be compatibility issues.