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

DM-23173: change W504 to W503 and fix the resulting flake8 warnings #510

Merged
merged 2 commits into from Jan 24, 2020

Conversation

r-owen
Copy link
Contributor

@r-owen r-owen commented Jan 23, 2020

No description provided.

@r-owen r-owen requested a review from timj January 23, 2020 22:37
@r-owen
Copy link
Contributor Author

r-owen commented Jan 23, 2020

The afw Python unit tests all pass, so I think it is safe to review.

However, Jenkins is still running (and I won't merge until it passes): https://ci.lsst.codes/blue/organizations/jenkins/stack-os-matrix/detail/stack-os-matrix/31070/pipeline/

If you'd rather wait for Jenkins to finish, that's fine.

Copy link
Member

@timj timj left a comment

Choose a reason for hiding this comment

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

Good cleanups. My main comment is that using f-strings in places would remove the need for the + operators completely for strings.

@@ -142,8 +142,8 @@ def validate(self):
return
if len(self.coeffs) == 1 or self.coeffs[0] != 0 or self.coeffs[1] == 0:
raise RuntimeError(
"invalid radial transform coeffs %s: " % (self.coeffs,) +
"need len(coeffs)=0 or len(coeffs)>1, coeffs[0]==0, "
"invalid radial transform coeffs %s: " % (self.coeffs,)
Copy link
Member

Choose a reason for hiding this comment

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

If you changed these lines to f-strings you could remove the + completely.

afwDisplay.Display(frame=frame).mtv(bkgdImage, title=self._testMethodName + " bkgdImage: " +
interpStyle.__str__())
afwDisplay.Display(frame=frame).mtv(bkgdImage, title=self._testMethodName + " bkgdImage: "
+ interpStyle.__str__())
Copy link
Member

Choose a reason for hiding this comment

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

consider an f-string here to allow the both of the + to go away.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note that an f-string does make the line very long (in fact I have to move title=f"..." to the next line). But it squeaks by.

Copy link
Member

Choose a reason for hiding this comment

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

You can split the f-string over two lines like any other explicit quoted string. You don't need the + to do it though.

if (foot.getBBox().getMinX() == 0
or foot.getBBox().getMaxX() == self.im.getWidth() - 1
or foot.getBBox().getMinY() == 0
or foot.getBBox().getMaxY() == self.im.getHeight() - 1):
Copy link
Member

Choose a reason for hiding this comment

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

This reorganization does look easier to read.

@@ -870,12 +869,10 @@ def basicTestComputeImageRaise(self, kernel, doRaise, kernelDescr=""):
try:
kernel.computeImage(kImage, True)
if doRaise:
self.fail(kernelDescr +
".computeImage should have raised an exception")
self.fail(kernelDescr + ".computeImage should have raised an exception")
Copy link
Member

Choose a reason for hiding this comment

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

f-string?

except pexExcept.Exception:
if not doRaise:
self.fail(kernelDescr +
".computeImage should not have raised an exception")
self.fail(kernelDescr + ".computeImage should not have raised an exception")
Copy link
Member

Choose a reason for hiding this comment

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

f-string?

afwDisplay.Display(frame=1).mtv(im, title=algorithm +
": diff image (dx, dy) = (%f, %f)" % (dx, dy))
afwDisplay.Display(frame=1).mtv(im, title=algorithm
+ ": diff image (dx, dy) = (%f, %f)" % (dx, dy))
Copy link
Member

Choose a reason for hiding this comment

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

f-string?

@r-owen
Copy link
Contributor Author

r-owen commented Jan 23, 2020

I will add f-strings where you suggest. I initially did not because it makes the code different than surrounding code and there are over 400 instances of % formatted strings in afw and I didn't want to change them all.

@r-owen
Copy link
Contributor Author

r-owen commented Jan 24, 2020

I would like to make the f string changes a separate commit in order to avoid mixing f strings and % formatting in the files.

@r-owen r-owen merged commit d2f60f3 into master Jan 24, 2020
@r-owen r-owen deleted the tickets/DM-23173-afw branch January 24, 2020 17:09
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.

None yet

2 participants