Skip to content

Flake8 all the things - #974

Closed
dorianpula wants to merge 16 commits into
paramiko:masterfrom
dorianpula:flake8-all-the-things
Closed

dorianpula wants to merge 16 commits into
paramiko:masterfrom
dorianpula:flake8-all-the-things

Conversation

@dorianpula

Copy link
Copy Markdown
Contributor

Introduce and make sure the Paramiko code passes Flake 8 check.
The setup is similar to what Invoke and Fabric use.

Notes:

  • Tests and demo code is not included.
  • Tried to avoid refactoring code unless it was absolutely necessary.

@bitprophet

Copy link
Copy Markdown
Member

Thanks again for tackling this! So excited.

Wishing in retrospect I'd had you start on the 1.17 or 1.18 branch, but nbd - this is the lion's share of the work - I can take care of trying to backport (or just...not...rolling forwards is a thing.)

I'll muck around with this momentarily, add to Travis, etc.

@bitprophet

Copy link
Copy Markdown
Member

Rebasing to 2.0 locally, going beyond that seems a fool's errand. Then layering more modern/house style on top, mostly removing backslash line continuations in favor of parentheticals.

@bitprophet bitprophet closed this in a46aaca Jun 1, 2017
@bitprophet

Copy link
Copy Markdown
Member

Also had to tweak flake8 version to work on 2.6...still waiting to see if that is enough to please the Travis gods.

@bitprophet

Copy link
Copy Markdown
Member

Green yey

Comment thread paramiko/auth_handler.py
maj_status = m.get_int()
min_status = m.get_int()
err_msg = m.get_string()
lang_tag = m.get_string() # we don't care!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess this can be dropped because an exception is immediately raised?

(It's worth pointing out the non-whitespace changes for a more careful review.)

Comment thread paramiko/auth_handler.py
self.transport._log(
WARNING,
'Auth rejected because the client attempted to change '
'username in mid-flight')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

In some projects it's allowed to exceed the line-length for log messages and the like, so that if you e.g. grep for something like "change username in mid-flight" after seeing it in a log line, you find it.

Comment thread paramiko/auth_handler.py
def _parse_userauth_banner(self, m):
banner = m.get_string()
self.banner = banner
lang = m.get_string()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

just pointing out another not-just-whitespace change (which is probably OK)
(but you can't always drop m.get_string() when the result is unused, because it mutates m)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yea this feels like an oops to me, I think probably best to be consistent with the change in kex_gss.py, where we just do a discarded m.get_string().

Comment thread paramiko/hostkeys.py
return ret

def __delitem__(self, key):
pass # Needed for instantiating HostKeys.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a minor functional change here - previously an exception would be thrown if the key was not found, now it won't

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yea we couldn't figure out what the heck was going on with the original change (happened in the Python 3 shakeup). Originally we just nuked it but I guess Dorian found it was added on purpose. I don't really see why we couldn't make it actually do del self[key] tho...

Comment thread paramiko/kex_gss.py
min_status = m.get_int()
err_msg = m.get_string()
lang_tag = m.get_string() # we don't care about the language!
m.get_string() # we don't care about the language!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

interesting that unused m string was handled differently here (even though it also immediately raises an exception)

Comment thread paramiko/server.py
:see: : `.ssh_gss`
"""
UseGSSAPI = False
GSSAPICleanupCredentials = False

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is an odd one - also set in a test and an example, but never used anywhere (removal looks correct)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

If it's set in test and example but not a functional API member, should probably nuke from those latter as well.

Comment thread paramiko/server.py
self.__transport._log(
ERROR,
'Exception in subsystem handler for "{}": {}'.format(
self.__name, e))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a format style change, uncommon in this PR

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

But not a bad change IMHO, {} > %s.

Comment thread paramiko/sftp_client.py
)

return size
return file_size

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

looks like a bug fix

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

... in fact it's just extraneous, the real return is above in the with: context. if that fails, an exception will be thrown. this return will never be hit

(but it's fine to just appease flake8 for now)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd rather just nuke it now that we've figured that out, tbh :D

Comment thread paramiko/sftp_client.py

# can not rewrite this to deal with E721, either as a None check
# nor as not an instance of None or NoneType
if fileobj is not type(None): # noqa

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

good catch here

Comment thread paramiko/sftp_server.py
raise Exception('unknown type for ' + repr(item) + ' type ' + repr(type(item)))
raise Exception(
'unknown type for {!r} type {!r}'.format(
item, type(item)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

interesting format style change (looks fine)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 here

Comment thread paramiko/transport.py
# along with Paramiko; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.

# flake8: noqa

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

a bunch of changes were made below to appease flake8, is this a leftover from partway through the process?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Seems likely, let's nuke it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I tried doing Flake8 for this module, and it was just overwhelming. Hence the cop-out and I skipped checking the entire module. A better approach would be to break out some of the deeply nested code into separate functions, but I wanted to concentrate on doing this in a separate PR.

@bitprophet

Copy link
Copy Markdown
Member

Thanks for the post-review, @ploxiln - I admit I took most of it on faith due to size & having been physically present during much of the work 😁

I've replied to most of the inline notes & I'll go through and tidy them all up soon unless somebody else beats me to it. (I supplied a lot of similar post-merge changes yesterday, as well, with lots of style tweaks like removal of most line continuations.)

@ploxiln

ploxiln commented Jun 1, 2017

Copy link
Copy Markdown
Contributor

I did notice your follow-up style changes - they did improve the line-wrapping considerably :)

@bitprophet

Copy link
Copy Markdown
Member

I was unpleasantly surprised at how many I had to leave in, though, because I honestly couldn't say the alternatives were actually better. Usually indicative of deeper code smells that required more time to truly fix!

@bitprophet

Copy link
Copy Markdown
Member

Working on those updates now.

@bitprophet

Copy link
Copy Markdown
Member

Ah, the flake8: noqa in transport.py was because there's still about 89 violations in the file (mostly line length). Will see if it's something I can tackle or if it's worth leaving it as-is.

@bitprophet

Copy link
Copy Markdown
Member

OK that's all done now?! Waiting on Travis to agree.

@ploxiln

ploxiln commented Jun 1, 2017

Copy link
Copy Markdown
Contributor

👍

@ploxiln

ploxiln commented Jun 1, 2017

Copy link
Copy Markdown
Contributor

found bug in b99b234 - should not all be {0}

@@ -108,7 +109,7 @@ class BadHostKeyException (SSHException):
     .. versionadded:: 1.6
     """
     def __init__(self, hostname, got_key, expected_key):
-        message = 'Host key for server {} does not match: got {} expected {}'
+        message = 'Host key for server {0} does not match: got {0}, expected {0}' # noqa
         message = message.format(
             hostname, got_key.get_base64(),
             expected_key.get_base64())

@dorianpula

Copy link
Copy Markdown
Contributor Author

@bitprophet It looks like master will get green once the transport.py is fixed up. 😞

Is there anything else I can help with flake8? Or I can jump on something else...

@bitprophet

bitprophet commented Jun 1, 2017 •

Copy link
Copy Markdown
Member

@ploxiln thought I fixed all of those, will double check...EDIT: yup I did miss one, pushed fix, thx!

@dorianpula Don't think so, I think this is pretty much licked now!

@bitprophet

Copy link
Copy Markdown
Member

Looks green ✅

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.

3 participants