lint: Up-rev hacking

Last time we did this was nearly 4 years ago; drag ourselves into
something approaching the present. Address a few new pyflakes issues
that seem reasonable to enforce:

   E275 missing whitespace after keyword
   E231 missing whitespace after ','
   E721 do not compare types, for exact checks use `is` / `is not`,
        for instance checks use `isinstance()`

Main motivator is that the old hacking kept us on an old version
of flake8 et al., which no longer work with newer Pythons.

Change-Id: I54b46349fabb9776dcadc6def1cfb961c123aaa0
This commit is contained in:
Tim Burke 2024-02-07 22:27:13 +00:00
parent 1936f6735c
commit 76ca11773e
18 changed files with 31 additions and 26 deletions

View File

@ -19,8 +19,9 @@ from swift.common.utils import public
from swift.common.middleware.s3api.exception import ACLError
from swift.common.middleware.s3api.controllers.base import Controller
from swift.common.middleware.s3api.s3response import HTTPOk, S3NotImplemented,\
MalformedACLError, UnexpectedContent, MissingSecurityHeader
from swift.common.middleware.s3api.s3response import (
HTTPOk, S3NotImplemented, MalformedACLError, UnexpectedContent,
MissingSecurityHeader)
from swift.common.middleware.s3api.etree import Element, SubElement, tostring
from swift.common.middleware.s3api.acl_utils import swift_acl_translate, \
XMLNS_XSI

View File

@ -18,8 +18,8 @@ from swift.common.utils import public
from swift.common.middleware.s3api.controllers.base import Controller, \
bucket_operation
from swift.common.middleware.s3api.etree import Element, tostring
from swift.common.middleware.s3api.s3response import HTTPOk, S3NotImplemented,\
NoLoggingStatusForKey
from swift.common.middleware.s3api.s3response import (
HTTPOk, S3NotImplemented, NoLoggingStatusForKey)
class LoggingStatusController(Controller):

View File

@ -1602,7 +1602,7 @@ class StaticLargeObject(object):
vrs, account, _junk = req.split_path(2, 3, True)
new_env = req.environ.copy()
new_env['REQUEST_METHOD'] = 'GET'
del(new_env['wsgi.input'])
del new_env['wsgi.input']
new_env['QUERY_STRING'] = 'multipart-manifest=get'
if 'version-id' in req.params:
new_env['QUERY_STRING'] += \

View File

@ -160,7 +160,7 @@ class BaseStoragePolicy(object):
object_ring=None, aliases='',
diskfile_module='egg:swift#replication.fs'):
# do not allow BaseStoragePolicy class to be instantiated directly
if type(self) == BaseStoragePolicy:
if type(self) is BaseStoragePolicy:
raise TypeError("Can't instantiate BaseStoragePolicy directly")
# policy parameter validation
try:

View File

@ -5568,7 +5568,7 @@ class ShardRangeList(UserList):
def __getitem__(self, index):
# workaround for py3 - not needed for py2.7,py3.8
result = self.data[index]
return ShardRangeList(result) if type(result) == list else result
return ShardRangeList(result) if type(result) is list else result
@property
def lower(self):
@ -6365,7 +6365,7 @@ class Watchdog(object):
:param key: timeout id, as returned by start()
"""
try:
del(self._timeouts[key])
del self._timeouts[key]
except KeyError:
pass

View File

@ -3,7 +3,7 @@
# process, which may cause wedges in the gate later.
# Hacking already pins down pep8, pyflakes and flake8
hacking>=2.0,<2.1.0 # Apache-2.0
hacking>=2.0,<6.2.0 # Apache-2.0
coverage>=5.0.4 # Apache-2.0
pytest>=4.6.11 # MIT
pytest-cov>=2.12.1 # MIT

View File

@ -1987,7 +1987,7 @@ class TestRingBuilder(unittest.TestCase):
# test old devs but no meta
no_meta_builder = rb
for dev in no_meta_builder.devs:
del(dev['meta'])
del dev['meta']
fake_pickle.return_value = no_meta_builder
pickle.load = fake_pickle
builder = ring.RingBuilder.load('fake.builder', open=fake_open)

View File

@ -375,8 +375,8 @@ class TestInternalClient(unittest.TestCase):
user_agent = 'some_user_agent'
request_tries = 123
with mock.patch.object(
internal_client, 'loadapp', return_value=app) as mock_loadapp,\
with mock.patch.object(internal_client, 'loadapp',
return_value=app) as mock_loadapp, \
self.assertRaises(ValueError):
# First try with a bad arg
internal_client.InternalClient(
@ -432,8 +432,8 @@ class TestInternalClient(unittest.TestCase):
app = FakeSwift()
user_agent = 'some_user_agent'
with mock.patch.object(
internal_client, 'loadapp', return_value=app) as mock_loadapp,\
with mock.patch.object(internal_client, 'loadapp',
return_value=app) as mock_loadapp, \
self.assertRaises(ValueError) as cm:
internal_client.InternalClient(
conf_path, user_agent, 1, allow_modify_pipeline=True)
@ -775,7 +775,8 @@ class TestInternalClient(unittest.TestCase):
client = internal_client.InternalClient(
None, "some_agent", 3, use_replication_network=False,
app=fake_app)
with self.assertRaises(internal_client.UnexpectedResponse) as ctx,\
expected_error = internal_client.UnexpectedResponse
with self.assertRaises(expected_error) as ctx, \
mock.patch('swift.common.internal_client.sleep'):
# This is obvious strange tests to expect only 400 Bad Request
# but this test intended to avoid extra body drain if it's

View File

@ -267,7 +267,7 @@ def setup_servers(the_object_server=object_server, extra_conf=None):
{'X-Timestamp': ts,
'x-trans-id': 'test'})
resp = conn.getresponse()
assert(resp.status == 201)
assert resp.status == 201
# Create another account
# used for account-to-account tests
ts = normalize_timestamp(time.time())
@ -281,7 +281,7 @@ def setup_servers(the_object_server=object_server, extra_conf=None):
{'X-Timestamp': ts,
'x-trans-id': 'test'})
resp = conn.getresponse()
assert(resp.status == 201)
assert resp.status == 201
# Create containers, 1 per test policy
sock = connect_tcp(('localhost', prolis.getsockname()[1]))
fd = sock.makefile('rwb')

View File

@ -146,6 +146,9 @@ commands = bandit -c bandit.yaml -r swift -n 5
# it's not a bug that we aren't using all of hacking, ignore:
# H101: Use TODO(NAME)
# H202: assertRaises Exception too broad
# H211/H212: Use assert{Is,IsNot}instance
# H214: Use assertIn/NotIn ...
# H216: The unittest.mock module should be used rather than ...
# H301: one import per line
# H306: imports not in alphabetical order (time, os)
# H404: multi line docstring should start without a leading new line
@ -159,7 +162,7 @@ commands = bandit -c bandit.yaml -r swift -n 5
# Swift team needs to decide if they want to enable either of these:
# W503: line break before binary operator
# W504: line break after binary operator
ignore = H101,H202,H301,H306,H404,H405,H501,W503,W504,E402,E731,E741
ignore = H101,H202,H211,H212,H214,H216,H301,H306,H404,H405,H501,W503,W504,E402,E731,E741
exclude = .venv,.tox,dist,*egg
filename = *.py,bin/*
show-source = True