Small tweaks to simplify the code#325
Small tweaks to simplify the code#325guoqiao wants to merge 3 commits intoopenstack-charmers:masterfrom
Conversation
str.startswith can accept a tuple, no need to use for loop. Signed-off-by: Joe Guo <joe.guo@canonical.com>
simplify the logic of setup file path Signed-off-by: Joe Guo <joe.guo@canonical.com>
can return safe_load result directly, no need to update the result to another temp dict. Signed-off-by: Joe Guo <joe.guo@canonical.com>
ajkavanagh
left a comment
There was a problem hiding this comment.
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.
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.
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.
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.