From 1e0ab242cabcbe1fe673d8950ff857092d71127f Mon Sep 17 00:00:00 2001
From: Matthew Oliver <matt@oliver.net.au>
Date: Tue, 20 Feb 2024 16:21:50 +1100
Subject: [PATCH] lint: Up-rev hacking

Without up-reving hacking python 3.12 can't be used for pep8/flake8
checks. Also address a few new pyflakes issues that seem reasonable
to enforce:

   E275 missing whitespace after keyword
   H214 Use assertIn/NotIn(A, B) rather than
        assertTrue/False(A in/not in B)
   H211 do not compare types, use assert{Is,IsNot}Instance

Add F811 (redefinition of unused 'function'), as this check makes
client.py fail.

And noqa some longer lines that we're happy to carry.

Change-Id: Ic97698a310ffe7114b668b8c4bc0195f6997bb45
---
 swiftclient/shell.py          | 8 ++++----
 test-requirements.txt         | 2 +-
 test/unit/test_service.py     | 2 +-
 test/unit/test_shell.py       | 2 +-
 test/unit/test_swiftclient.py | 4 ++--
 tox.ini                       | 3 ++-
 6 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/swiftclient/shell.py b/swiftclient/shell.py
index c5fb2190..faa20001 100755
--- a/swiftclient/shell.py
+++ b/swiftclient/shell.py
@@ -754,7 +754,7 @@ def st_stat(parser, args, output_manager, return_parser=False):
                                     items, headers, output_manager
                                 )
                             else:
-                                raise(stat_result["error"])
+                                raise stat_result["error"]
                     else:
                         output_manager.error(
                             'Usage: %s stat %s\n%s', BASENAME,
@@ -768,7 +768,7 @@ st_post_options = '''[--read-acl <acl>] [--write-acl <acl>] [--sync-to <sync-to>
                   [--sync-key <sync-key>] [--meta <name:value>]
                   [--header <header>]
                   [<container> [<object>]]
-'''
+'''  # noqa
 
 st_post_help = '''
 Updates meta information for the account, container, or object.
@@ -864,7 +864,7 @@ def st_post(parser, args, output_manager, return_parser=False):
                 else:
                     result = swift.post(container=container)
             if not result["success"]:
-                raise(result["error"])
+                raise result["error"]
 
         except SwiftError as e:
             output_manager.error(e.value)
@@ -1520,7 +1520,7 @@ st_bash_completion_help = '''Retrieve command specific flags used by bash_comple
 
 Optional positional arguments:
   <command>           Swift client command to filter the flags by.
-'''.strip('\n')
+'''.strip('\n')  # noqa
 
 
 st_bash_completion_options = '''[command]
diff --git a/test-requirements.txt b/test-requirements.txt
index a4b64ee7..63909c63 100644
--- a/test-requirements.txt
+++ b/test-requirements.txt
@@ -1,4 +1,4 @@
-hacking>=3.2.0,<3.3.0 # Apache-2.0
+hacking>=3.2.0,<6.2.0 # Apache-2.0
 
 coverage!=4.4,>=4.0   # Apache-2.0
 keystoneauth1>=3.4.0  # Apache-2.0
diff --git a/test/unit/test_service.py b/test/unit/test_service.py
index 99351255..6bc50ca7 100644
--- a/test/unit/test_service.py
+++ b/test/unit/test_service.py
@@ -1330,7 +1330,7 @@ class TestService(unittest.TestCase):
             options)
         responses = [x for x in resp_iter]
         for resp in responses:
-            self.assertFalse('error' in resp)
+            self.assertNotIn('error', resp)
             self.assertTrue(resp['success'])
         self.assertEqual(5, len(responses))
         container_resp, segment_container_resp = responses[0:2]
diff --git a/test/unit/test_shell.py b/test/unit/test_shell.py
index 1bd26fff..71568d29 100644
--- a/test/unit/test_shell.py
+++ b/test/unit/test_shell.py
@@ -711,7 +711,7 @@ class TestShell(unittest.TestCase):
     @mock.patch('swiftclient.service.Connection')
     def test_download_shuffle(self, connection, mock_shuffle):
         # Test that the container and object lists are shuffled
-        mock_shuffle.side_effect = lambda l: l
+        mock_shuffle.side_effect = lambda to_shuffle: to_shuffle
         connection.return_value.get_object.return_value = [
             {'content-type': 'text/plain',
              'etag': EMPTY_ETAG},
diff --git a/test/unit/test_swiftclient.py b/test/unit/test_swiftclient.py
index be4f4a5e..3506a11d 100644
--- a/test/unit/test_swiftclient.py
+++ b/test/unit/test_swiftclient.py
@@ -2000,7 +2000,7 @@ class TestConnection(MockHttpTest):
                 'authurl': 'http://www.test.com',
                 'tenant_name': 'atenant'}
         conn = c.Connection(**args)
-        self.assertEqual(type(conn), c.Connection)
+        self.assertIsInstance(conn, c.Connection)
 
     def test_instance_kwargs_token(self):
         args = {'preauthtoken': 'atoken123',
@@ -3056,7 +3056,7 @@ class TestCloseConnection(MockHttpTest):
         conn = c.Connection(url, 'asdf', 'asdf')
         self.assertIsNone(conn.http_conn)
         conn.http_conn = c.http_connection(url)
-        self.assertEqual(type(conn.http_conn), tuple)
+        self.assertIsInstance(conn.http_conn, tuple)
         self.assertEqual(len(conn.http_conn), 2)
         http_conn_obj = conn.http_conn[1]
         self.assertIsInstance(http_conn_obj, c.HTTPConnection)
diff --git a/tox.ini b/tox.ini
index 3a6cd8a0..a2bf8a95 100644
--- a/tox.ini
+++ b/tox.ini
@@ -69,7 +69,8 @@ commands=
 # H404: multi line docstring should start without a leading new line
 # H405: multi line docstring summary not separated with an empty line
 # W504: line break after binary operator
-ignore = H101,H301,H306,H401,H403,H404,H405,W504
+# F811: Redefinition of unused name from line n
+ignore = H101,H301,H306,H401,H403,H404,H405,W504,F811
 # H106: Don’t put vim configuration in source files
 # H203: Use assertIs(Not)None to check for None
 enable-extensions=H106,H203