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

Better handling of empty/missing roster in config #112

Merged
merged 1 commit into from
Feb 7, 2018

Conversation

LinuxMercedes
Copy link
Member

No description provided.

brhoades
brhoades previously approved these changes Feb 4, 2018
return self.data[key]
raise e
# Fill in a blank roster if needed
if key == "roster" and (key not in self.data or self.data[key] is None):
Copy link
Member

Choose a reason for hiding this comment

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

Is self.data a property? I can't remember. My intuition here is to tell you to use self.data.get(key, None) or self.data.get(key) which defaults to None (or it did in Python 2).

Copy link
Member Author

Choose a reason for hiding this comment

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

Calling self.data.get(key, []) doesn't set self.data[key] = [], so any modifications to the empty roster list returned wouldn't actually show up in the config.

Example:

>>> data = {}
>>> l = data.get("bob", [])
>>> l
[]
>>> data
{}
>>> l.append(5)
>>> l
[5]
>>> data
{}

Copy link
Member Author

Choose a reason for hiding this comment

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

Ohh, I see what you mean. Yeah, I'll change the condition--yours is a lot nicer. ❤️

if key == "roster":
self.data[key] = []
return self.data[key]
raise e
Copy link
Member

Choose a reason for hiding this comment

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

This is more Pythonic. Without reading into it more, why are we nuking it?

Copy link
Member Author

Choose a reason for hiding this comment

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

This check fails to catch the self.data['roster'] is None case.

@LinuxMercedes LinuxMercedes merged commit c2e1300 into master Feb 7, 2018
@LinuxMercedes LinuxMercedes deleted the pr/better-roster-handling branch February 7, 2018 02:40
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.

2 participants