-
Notifications
You must be signed in to change notification settings - Fork 5
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
Create __repr__
for site_config classes
#335
base: main
Are you sure you want to change the base?
Conversation
So ... yes, I think it's safe at this point to remove .from_dict and just make that the default constructor. Can you consider this approach, instead of caching the input data dict?
The problems with caching data are that the input dict and the instance attributes can get out of sync. In practice that's not very likely. But it would be confusing to have the repr be inaccurate. It would also be dangerous to have consumers of this config info start to use .whatever and .data['whatever'] interchangeably. Some of the site_config classes will be quite amenable to the |
Great, how do you want me to handle that with respect to this PR? Include it? Separate? Before/After this one? (Hopefully after, since I've done that already on top of this branch.)
I see your point about using the cached data attribute, but also think it's unlikely in practice that that falls out of sync. Some thoughts on using
|
Whatever you like. Include is fine; later is fine.
Agreed.
Yes. Constructing a valid data dict on the fly will be easier in cases that don't have many keys.
That doesn't bother me much. I won't usually be trying to construct new SiteConfig objects from old reprs I have lying around. But honestly a super long repr like this is just going to annoy me most of the time. I would rather cache the input dict in _data, and if I need to access it, print(sc._data). I'm don't feel super strongly about this... none of the solutions is totally satisfactory. Go ahead with what seems most useful to you. |
Description
This PR creates
__repr__
methods for each of thesite_config.py
classes. The returned string can be used to recreate the Config object with the exception of including theparent
, which we leave out. (It created quite large representations.) (On that note -- why do we track the parent? As pointed out in the docs, it's never used.)Questions
I had one question/comment about these classes while working on this. Why do we have all of these alternative constructor classmethods when mostly there is only one way (
.from_dict()
) to construct the object anyway?I thought it would make more sense to have the constructor in
.from_dict()
be the default constructor, as that would clean up the__repr__
a bit. This leavesSiteConfig.from_yaml()
as the only alternative constructor.I was going to include in this PR, but it makes things sort of messy for reviewing the
__repr__
work. You can see this rework here.If that makes sense, I can PR that change as well.
Motivation and Context
A few times recently I've needed to debug something related to these objects and having a way to easily print their contents is extremely useful in that case.
How Has This Been Tested?
I wrote some tests while doing this, which use a shared dummy config that is written in the test. They mostly just assert that
cfg.data == data
essentially, which isn't particularly useful, but does test the objects can be made...Types of changes
Checklist: