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

Miscellaneous minor tune ups, shouldn't effect functioning #100

Merged
merged 5 commits into from
Aug 10, 2018

Conversation

yarikoptic
Copy link
Contributor

I was just looking at the code so introduced some minor changes for consistency (within, with PEP-8, and with jupyterhub). Feel free to ignore/discard.

if self.job_status and re.search(self.state_running_re, self.job_status):
return True
else: return False
return bool(self.job_status and re.search(self.state_running_re, self.job_status))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these two should be the only possibly "functional" changes

@rkdarst
Copy link
Contributor

rkdarst commented Jul 6, 2018

Looks good to me, though I'm not a maintainer of this. The travis failure seems to be a random timeout issue.

@yarikoptic
Copy link
Contributor Author

Thanks @rkdarst ... unfortunately I do not have super powers to restart that job to confirm that it was something intermittent, so would need the maintainer(s) to restart it

@mbmilligan
Copy link
Member

Re-running now

Copy link
Contributor

@willingc willingc left a comment

Choose a reason for hiding this comment

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

@yarikoptic Thanks for the PR. A few corrections to the PR and then it should be ready to approve. Thanks.

@@ -334,7 +335,7 @@ def start(self):
if self.user and self.user.server and self.user.server.port:
self.port = self.user.server.port
self.db.commit()
elif (jupyterhub.version_info < (0,7) and not self.user.server.port) or \
elif (jupyterhub.version_info < (0,7) and not self.user.server.port) or \
Copy link
Contributor

Choose a reason for hiding this comment

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

Hi @yarikoptic, In general, we discourage PRs that are primarily style changes. In this case, I'm happy to be rid of the \. You may as well go ahead and eliminate the \ here by placing outer parens on both conditionals.

Copy link
Contributor

Choose a reason for hiding this comment

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

Alternatively:

elif (jupyterhub.version_info < (0,7) and not self.user.server.port) or (
    jupyterhub.version_info >= (0,7) and not self.port
):

if self.job_status and re.search(self.state_pending_re, self.job_status):
return True
else: return False
return bool(self.job_status and re.search(self.state_pending_re, self.job_status))
Copy link
Contributor

Choose a reason for hiding this comment

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

I recommend leaving as currently written but clean up the else statement to put the return on a separate line.

By adding the bool(), Python will not short-circuit the expression if self.job_status evaluates as false and will do the regex search even if not needed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Are you sure @willingc about the differently behaving "short-circuit" between if and bool? I am not aware of any difference in this case since in both cases it needs first to evaluate the conditional for its bool value, and thus it would short-circuit (stop evaluating as soon as the first one evaluates to False) in either of the cases... Since I trust no-one, including myself, here is a quick demo to support that:

$> cat /tmp/shortc.py 
def func(x):
    print("in func")
    return bool(x)

import sys

b = bool(int(sys.argv[1]))
v = int(sys.argv[2])
print("b=%r v=%r" % (b,v))

if b and func(v):
    print("if True")
else:
    print("if False")

print("bool %s" % bool(b and func(v)))

$> python3.7 /tmp/shortc.py 0 1
b=False v=1
if False
bool False

$> python3.7 /tmp/shortc.py 1 1
b=True v=1
in func
if True
in func
bool True

$> python3.7 /tmp/shortc.py 1 0
b=True v=0
in func
if False
in func
bool False

$> python3.7 /tmp/shortc.py 0 0
b=False v=0
if False
bool False

The only advantage I see if of the original way (and I will change back now, since I do not have strong opinion on this) is that you could easier monitor the coverage -- which of the cases was triggered by the tests code, and which possibly not, which isn't possible if it is just a one line expression

@yarikoptic
Copy link
Contributor Author

done, pushed tuneups, Cheers!

@minrk minrk merged commit 5a9d6e8 into jupyterhub:master Aug 10, 2018
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.

5 participants