Upgrade flake8

Update to the latest flake8, and fix all code warnings related to that.
This commit is contained in:
Hugo Osvaldo Barrera 2020-06-08 18:03:10 +02:00
parent aafafaa501
commit 7e4a0be674
9 changed files with 42 additions and 38 deletions

View file

@ -82,7 +82,7 @@ install-test: install-servers
[ -z "$(TEST_EXTRA_PACKAGES)" ] || pip install $(TEST_EXTRA_PACKAGES) [ -z "$(TEST_EXTRA_PACKAGES)" ] || pip install $(TEST_EXTRA_PACKAGES)
install-style: install-docs install-style: install-docs
pip install -U flake8==3.5.0 flake8-import-order 'flake8-bugbear>=17.3.0' autopep8 pip install -U flake8 flake8-import-order flake8-bugbear autopep8
style: style:
flake8 flake8

View file

@ -9,6 +9,8 @@ addopts = --tb=short
# E731: Use a def instead of lambda expr # E731: Use a def instead of lambda expr
# E743: Ambiguous function definition # E743: Ambiguous function definition
ignore = E731, E743 ignore = E731, E743
# E503: Line break occurred before a binary operator
extend-ignore = W503
select = C,E,F,W,B,B9 select = C,E,F,W,B,B9
exclude = .eggs, tests/storage/servers/owncloud/, tests/storage/servers/nextcloud/, tests/storage/servers/baikal/, build/ exclude = .eggs, tests/storage/servers/owncloud/, tests/storage/servers/nextcloud/, tests/storage/servers/baikal/, build/
application-package-names = tests,vdirsyncer application-package-names = tests,vdirsyncer

View file

@ -140,13 +140,13 @@ class TestCalDAVStorage(DAVStorageTests):
task = s.upload(format_item(TASK_TEMPLATE))[0] task = s.upload(format_item(TASK_TEMPLATE))[0]
s.item_types = ('VTODO', 'VEVENT') s.item_types = ('VTODO', 'VEVENT')
def l(): def hrefs():
return set(href for href, etag in s.list()) return {href for href, etag in s.list()}
assert l() == {event, task} assert hrefs() == {event, task}
s.item_types = ('VTODO',) s.item_types = ('VTODO',)
assert l() == {task} assert hrefs() == {task}
s.item_types = ('VEVENT',) s.item_types = ('VEVENT',)
assert l() == {event} assert hrefs() == {event}
s.item_types = () s.item_types = ()
assert l() == {event, task} assert hrefs() == {event, task}

View file

@ -67,10 +67,10 @@ class TestFilesystemStorage(StorageTests):
calls = [] calls = []
exe = 'foo' exe = 'foo'
def check_call_mock(l, *args, **kwargs): def check_call_mock(call, *args, **kwargs):
calls.append(True) calls.append(True)
assert len(l) == 2 assert len(call) == 2
assert l[0] == exe assert call[0] == exe
monkeypatch.setattr(subprocess, 'call', check_call_mock) monkeypatch.setattr(subprocess, 'call', check_call_mock)
@ -82,5 +82,5 @@ class TestFilesystemStorage(StorageTests):
tmpdir.mkdir('.git').mkdir('foo') tmpdir.mkdir('.git').mkdir('foo')
tmpdir.mkdir('a') tmpdir.mkdir('a')
tmpdir.mkdir('b') tmpdir.mkdir('b')
assert set(c['collection'] for c assert {c['collection'] for c
in self.storage_class.discover(str(tmpdir))) == {'a', 'b'} in self.storage_class.discover(str(tmpdir))} == {'a', 'b'}

View file

@ -22,9 +22,9 @@ _simple_split = [
] ]
_simple_joined = u'\r\n'.join( _simple_joined = u'\r\n'.join(
[u'BEGIN:VADDRESSBOOK'] + [u'BEGIN:VADDRESSBOOK']
_simple_split + + _simple_split
[u'END:VADDRESSBOOK\r\n'] + [u'END:VADDRESSBOOK\r\n']
) )
@ -40,9 +40,9 @@ def test_split_collection_simple(benchmark):
def test_split_collection_multiple_wrappers(benchmark): def test_split_collection_multiple_wrappers(benchmark):
joined = u'\r\n'.join( joined = u'\r\n'.join(
u'BEGIN:VADDRESSBOOK\r\n' + u'BEGIN:VADDRESSBOOK\r\n'
x + + x
u'\r\nEND:VADDRESSBOOK\r\n' + u'\r\nEND:VADDRESSBOOK\r\n'
for x in _simple_split for x in _simple_split
) )
given = benchmark(lambda: list(vobject.split_collection(joined))) given = benchmark(lambda: list(vobject.split_collection(joined)))
@ -118,19 +118,19 @@ def test_split_collection_timezones():
) )
full = u'\r\n'.join( full = u'\r\n'.join(
[u'BEGIN:VCALENDAR'] + [u'BEGIN:VCALENDAR']
items + + items
[timezone, u'END:VCALENDAR'] + [timezone, u'END:VCALENDAR']
) )
given = set(normalize_item(item) given = {normalize_item(item)
for item in vobject.split_collection(full)) for item in vobject.split_collection(full)}
expected = set( expected = {
normalize_item(u'\r\n'.join(( normalize_item(u'\r\n'.join((
u'BEGIN:VCALENDAR', item, timezone, u'END:VCALENDAR' u'BEGIN:VCALENDAR', item, timezone, u'END:VCALENDAR'
))) )))
for item in items for item in items
) }
assert given == expected assert given == expected

View file

@ -64,7 +64,7 @@ def _validate_collections_param(collections):
e = ValueError( e = ValueError(
'Expected list of format ' 'Expected list of format '
'["config_name", "storage_a_name", "storage_b_name"]' '["config_name", "storage_a_name", "storage_b_name"]'
.format(len(collection))) )
if len(collection) != 3: if len(collection) != 3:
raise e raise e

View file

@ -70,9 +70,10 @@ class SingleFileStorage(Storage):
args['path'] = subpath args['path'] = subpath
collection_end = ( collection_end = (
placeholder_pos + placeholder_pos
2 + # length of '%s' + 2 # length of '%s'
len(subpath) - len(path) + len(subpath)
- len(path)
) )
collection = subpath[placeholder_pos:collection_end] collection = subpath[placeholder_pos:collection_end]
args['collection'] = collection args['collection'] = collection
@ -162,10 +163,11 @@ class SingleFileStorage(Storage):
def _write(self): def _write(self):
if self._last_etag is not None and \ if self._last_etag is not None and \
self._last_etag != get_etag_from_file(self.path): self._last_etag != get_etag_from_file(self.path):
raise exceptions.PreconditionFailed( raise exceptions.PreconditionFailed((
'Some other program modified the file {r!}. Re-run the ' 'Some other program modified the file {!r}. Re-run the '
'synchronization and make sure absolutely no other program is ' 'synchronization and make sure absolutely no other program is '
'writing into the same file.'.format(self.path)) 'writing into the same file.'
).format(self.path))
text = join_collection( text = join_collection(
item.raw for item, etag in self._items.values() item.raw for item, etag in self._items.values()
) )

View file

@ -74,9 +74,9 @@ class _StorageInfo(object):
new_meta = self.status.get_new(ident) new_meta = self.status.get_new(ident)
return ( return (
new_meta.etag != old_meta.etag and # etag changed new_meta.etag != old_meta.etag # etag changed
# item actually changed # item actually changed
(old_meta.hash is None or new_meta.hash != old_meta.hash) and (old_meta.hash is None or new_meta.hash != old_meta.hash)
) )
def set_item_cache(self, ident, item): def set_item_cache(self, ident, item):

View file

@ -375,8 +375,8 @@ class _Component(object):
def __eq__(self, other): def __eq__(self, other):
return ( return (
isinstance(other, type(self)) and isinstance(other, type(self))
self.name == other.name and and self.name == other.name
self.props == other.props and and self.props == other.props
self.subcomponents == other.subcomponents and self.subcomponents == other.subcomponents
) )