-
Notifications
You must be signed in to change notification settings - Fork 47
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
Small tweaks to simplify the code #325
base: master
Are you sure you want to change the base?
Conversation
str.startswith can accept a tuple, no need to use for loop. Signed-off-by: Joe Guo <[email protected]>
simplify the logic of setup file path Signed-off-by: Joe Guo <[email protected]>
can return safe_load result directly, no need to update the result to another temp dict. Signed-off-by: Joe Guo <[email protected]>
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.
Nice set of optimisations; I love the code gardening and it does improve/simplify the code.
One comment re a semantic/logic change in the code that I think needs addressing. Thanks!
ZAZA_SETUP_FILE_LOCATIONS = [ | ||
'{home}/.zaza.yaml'] | ||
expandvars('$HOME/.zaza.yaml'), | ||
] |
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.
In the same way as line 35 change, this could also be a tuple.
However, I would leave out the expandvars()
call here, and delay it to where the string is used. This is because it's just about possible that the HOME
env will change between load time of the module and use time of the function.
valid = True | ||
break | ||
return valid | ||
return key.startswith(VALID_ENVIRONMENT_KEY_PREFIXES) |
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.
Nice optimisation; might be useful to add a comment indicating that .startswith()
can also take the tuple of values to match against (which I didn't know about! - TIL!)
if os.path.isfile(setup_file): | ||
return setup_file |
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 the expandvars()
call here to be consistent with the current semantics of the function; i.e. evaluate the HOME
env in this function rather than at module load time.
No description provided.