From 7eb123595bdcb4667c827a58ba8e80f06f0ad6f9 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sun, 25 Feb 2018 21:23:29 +0000 Subject: [PATCH 1/4] core: Implement Dead.__ne__ & Dead.__hash__ Both these addtions are to address warnings in https://lgtm.com/projects/g/dw/mitogen/alerts/?mode=list. Namely that if a class defines an equality method then it should also define an inequality and a hash method. Refs #61 --- mitogen/core.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mitogen/core.py b/mitogen/core.py index d8ffbb13..5419f2a7 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -121,9 +121,15 @@ class TimeoutError(Error): class Dead(object): + def __hash__(self): + return hash(Dead) + def __eq__(self, other): return type(other) is Dead + def __ne__(self, other): + return type(other) is not Dead + def __reduce__(self): return (_unpickle_dead, ()) From 7d4317b2792cdc9df2e0399adca893dd469a9f23 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sun, 25 Feb 2018 21:38:46 +0000 Subject: [PATCH 2/4] compat: ignore LGTM checks on third party Refs #61 --- .lgtm.yml | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .lgtm.yml diff --git a/.lgtm.yml b/.lgtm.yml new file mode 100644 index 00000000..3e45b21e --- /dev/null +++ b/.lgtm.yml @@ -0,0 +1,3 @@ +path_classifiers: + thirdparty: + - "mitogen/compat/*.py" From be0b997a4cf59781e9da30a771c972cf7bd26b6e Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sun, 25 Feb 2018 21:53:16 +0000 Subject: [PATCH 3/4] ssh, sudo: Remove redundant else clause on bootstrap loop Since the for loops don't contain any break statements the StreamErrors will always be raised when the loop completes without the method resturning. See https://lgtm.com/rules/5980098/ Refs #61 --- mitogen/ssh.py | 3 +-- mitogen/sudo.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/mitogen/ssh.py b/mitogen/ssh.py index a1bc8f18..1db34d5c 100644 --- a/mitogen/ssh.py +++ b/mitogen/ssh.py @@ -126,5 +126,4 @@ class Stream(mitogen.parent.Stream): LOG.debug('sending password') self.transmit_side.write(self.password + '\n') password_sent = True - else: - raise mitogen.core.StreamError('bootstrap failed') + raise mitogen.core.StreamError('bootstrap failed') diff --git a/mitogen/sudo.py b/mitogen/sudo.py index 808f459d..78b9dd7b 100644 --- a/mitogen/sudo.py +++ b/mitogen/sudo.py @@ -107,5 +107,4 @@ class Stream(mitogen.parent.Stream): LOG.debug('sending password') os.write(self.transmit_side.fd, self.password + '\n') password_sent = True - else: - raise mitogen.core.StreamError('bootstrap failed') + raise mitogen.core.StreamError('bootstrap failed') From 5d0ae768d85280d7197fd9f663e7acf5d0803912 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sun, 25 Feb 2018 22:43:26 +0000 Subject: [PATCH 4/4] parent: Fix ModuleForwarder not sending related packages Found due to a LGTM warning about unused loop variable (related). As far as I can tell the callback was sending fullname multiple times. KeyError check added because I found NestedTest failed - mitogen.parent had mitogen as one of it's related, and mitogen was not in the cache. Refs #61 --- mitogen/parent.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/mitogen/parent.py b/mitogen/parent.py index 53be0726..3966c34b 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -519,7 +519,14 @@ class ModuleForwarder(object): tup = self.importer._cache[fullname] if tup is not None: for related in tup[4]: - rtup = self.importer._cache[fullname] + LOG.debug('%r._on_get_module(): trying related %r', + self, related) + try: + rtup = self.importer._cache[related] + except KeyError: + LOG.warn('%r._on_get_module(): skipping %r, not in cache', + self, related) + continue self._send_one_module(msg, rtup) self._send_one_module(msg, tup)