From 109feec6d5d7f37356706fa7286fb7cfb6b9a280 Mon Sep 17 00:00:00 2001 From: Alex Willmer Date: Sat, 23 Apr 2022 08:33:52 +0100 Subject: [PATCH] Fix lints found by flake8 --- ansible_mitogen/connection.py | 2 +- ansible_mitogen/planner.py | 18 ++++++++++-------- mitogen/core.py | 3 +-- mitogen/fakessh.py | 4 ++-- mitogen/parent.py | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/ansible_mitogen/connection.py b/ansible_mitogen/connection.py index 31518ef3..c91c8f72 100644 --- a/ansible_mitogen/connection.py +++ b/ansible_mitogen/connection.py @@ -1095,7 +1095,7 @@ class Connection(ansible.plugins.connection.ConnectionBase): s = fp.read(self.SMALL_FILE_LIMIT + 1) finally: fp.close() - except OSError: + except OSError as e: self._throw_io_error(e, in_path) raise diff --git a/ansible_mitogen/planner.py b/ansible_mitogen/planner.py index a277883f..4bf16074 100644 --- a/ansible_mitogen/planner.py +++ b/ansible_mitogen/planner.py @@ -297,11 +297,11 @@ class NewStylePlanner(ScriptPlanner): preprocessing the module. """ runner_name = 'NewStyleRunner' - MARKER = re.compile(b'from ansible(?:_collections|\.module_utils)\.') + MARKER = re.compile(br'from ansible(?:_collections|\.module_utils)\.') @classmethod def detect(cls, path, source): - return cls.MARKER.search(source) != None + return cls.MARKER.search(source) is not None def _get_interpreter(self): return None, None @@ -522,12 +522,15 @@ def _invoke_isolated_task(invocation, planner): context.shutdown() -def _get_planner(name, path, source): +def _get_planner(invocation, source): for klass in _planners: - if klass.detect(path, source): - LOG.debug('%r accepted %r (filename %r)', klass, name, path) + if klass.detect(invocation.module_path, source): + LOG.debug( + '%r accepted %r (filename %r)', + klass, invocation.module_name, invocation.module_path, + ) return klass - LOG.debug('%r rejected %r', klass, name) + LOG.debug('%r rejected %r', klass, invocation.module_name) raise ansible.errors.AnsibleError(NO_METHOD_MSG + repr(invocation)) @@ -590,8 +593,7 @@ def invoke(invocation): module_source = invocation.get_module_source() _fix_py35(invocation, module_source) _planner_by_path[invocation.module_path] = _get_planner( - invocation.module_name, - invocation.module_path, + invocation, module_source ) diff --git a/mitogen/core.py b/mitogen/core.py index d64f48fb..bee722e6 100644 --- a/mitogen/core.py +++ b/mitogen/core.py @@ -2717,7 +2717,7 @@ class Latch(object): raise e assert cookie == got_cookie, ( - "Cookie incorrect; got %r, expected %r" \ + "Cookie incorrect; got %r, expected %r" % (binascii.hexlify(got_cookie), binascii.hexlify(cookie)) ) @@ -3672,7 +3672,6 @@ class Dispatcher(object): self._service_recv.notify = None self.recv.close() - @classmethod @takes_econtext def forget_chain(cls, chain_id, econtext): diff --git a/mitogen/fakessh.py b/mitogen/fakessh.py index 63ee6453..2d660248 100644 --- a/mitogen/fakessh.py +++ b/mitogen/fakessh.py @@ -199,7 +199,7 @@ class Process(object): def _on_stdin(self, msg): if msg.is_dead: - IOLOG.debug('%r._on_stdin() -> %r', self, data) + IOLOG.debug('%r._on_stdin() -> %r', self, msg) self.pump.protocol.close() return @@ -436,7 +436,7 @@ def run(dest, router, args, deadline=None, econtext=None): fp.write(inspect.getsource(mitogen.core)) fp.write('\n') fp.write('ExternalContext(%r).main()\n' % ( - _get_econtext_config(context, sock2), + _get_econtext_config(econtext, sock2), )) finally: fp.close() diff --git a/mitogen/parent.py b/mitogen/parent.py index c3efe28a..32aa3cb6 100644 --- a/mitogen/parent.py +++ b/mitogen/parent.py @@ -1508,7 +1508,7 @@ class Connection(object): def get_preamble(self): suffix = ( - '\nExternalContext(%r).main()\n' %\ + '\nExternalContext(%r).main()\n' % (self.get_econtext_config(),) ) partial = get_core_source_partial()