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

Small tweaks to simplify the code #325

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

guoqiao
Copy link
Contributor

@guoqiao guoqiao commented Jan 29, 2020

No description provided.

Joe Guo added 3 commits January 29, 2020 17:41
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]>
Copy link
Collaborator

@ajkavanagh ajkavanagh left a 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!

Comment on lines 23 to +25
ZAZA_SETUP_FILE_LOCATIONS = [
'{home}/.zaza.yaml']
expandvars('$HOME/.zaza.yaml'),
]
Copy link
Collaborator

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)
Copy link
Collaborator

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!)

Comment on lines +131 to +132
if os.path.isfile(setup_file):
return setup_file
Copy link
Collaborator

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.

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