Skip to content

Commit ecb181d

Browse files
author
Hugo Osvaldo Barrera
authored
Merge pull request #925 from pimutils/pyupgrade
Set up pyupgrade
2 parents 8886854 + fed1ee6 commit ecb181d

File tree

19 files changed

+40
-62
lines changed

19 files changed

+40
-62
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ repos:
2222
hooks:
2323
- id: isort
2424
name: isort (python)
25+
- repo: https://github.com/asottile/pyupgrade
26+
rev: v2.23.3
27+
hooks:
28+
- id: pyupgrade
29+
args: [--py37-plus]
2530
- repo: https://github.com/pre-commit/mirrors-mypy
2631
rev: "v0.910"
2732
hooks:

setup.cfg

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
[wheel]
2-
universal = 1
3-
41
[tool:pytest]
52
addopts =
63
--tb=short

tests/storage/servers/davical/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"url": "https://brutus.lostpackets.de/davical-test/caldav.php/",
1212
}
1313
except KeyError as e:
14-
pytestmark = pytest.mark.skip("Missing envkey: {}".format(str(e)))
14+
pytestmark = pytest.mark.skip(f"Missing envkey: {str(e)}")
1515

1616

1717
@pytest.mark.flaky(reruns=5)

tests/storage/test_http_with_singlefile.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ def callback(url, headers, **kwargs):
6565
"""
6666
assert headers["User-Agent"].startswith("vdirsyncer/")
6767

68-
with open(self.tmpfile, "r") as f:
68+
with open(self.tmpfile) as f:
6969
body = f.read()
7070

7171
return CallbackResult(

tests/system/cli/test_repair.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_basic(storage, runner, collection):
3939
assert not result.exception
4040
assert "No UID" in result.output
4141
assert "'toobroken.txt' is malformed beyond repair" in result.output
42-
(new_fname,) = [x for x in storage.listdir() if "toobroken" not in str(x)]
42+
(new_fname,) = (x for x in storage.listdir() if "toobroken" not in str(x))
4343
assert "UID:" in new_fname.read()
4444

4545

tests/unit/sync/test_sync.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -561,7 +561,7 @@ async def get(href):
561561
_old_update = s.update
562562

563563
async def upload(item):
564-
return ((await _old_upload(item)))[0], "NULL"
564+
return (await _old_upload(item))[0], "NULL"
565565

566566
async def update(href, item, etag):
567567
return await _old_update(href, item, etag) and "NULL"

vdirsyncer/cli/config.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ def _validate_collections_param(collections):
8888
raise ValueError("Duplicate value.")
8989
collection_names.add(collection_name)
9090
except ValueError as e:
91-
raise ValueError(
92-
"`collections` parameter, position {i}: {e}".format(i=i, e=str(e))
93-
)
91+
raise ValueError(f"`collections` parameter, position {i}: {str(e)}")
9492

9593

9694
class _ConfigReader:
@@ -135,7 +133,7 @@ def parse(self):
135133
dict(_parse_options(self._parser.items(section), section=section)),
136134
)
137135
except ValueError as e:
138-
raise exceptions.UserError('Section "{}": {}'.format(section, str(e)))
136+
raise exceptions.UserError(f'Section "{section}": {str(e)}')
139137

140138
_validate_general_section(self._general)
141139
if getattr(self._file, "name", None):
@@ -152,7 +150,7 @@ def _parse_options(items, section=None):
152150
try:
153151
yield key, json.loads(value)
154152
except ValueError as e:
155-
raise ValueError('Section "{}", option "{}": {}'.format(section, key, e))
153+
raise ValueError(f'Section "{section}", option "{key}": {e}')
156154

157155

158156
class Config:
@@ -190,9 +188,7 @@ def from_filename_or_environment(cls, fname=None):
190188
with open(fname) as f:
191189
return cls.from_fileobject(f)
192190
except Exception as e:
193-
raise exceptions.UserError(
194-
"Error during reading config {}: {}".format(fname, e)
195-
)
191+
raise exceptions.UserError(f"Error during reading config {fname}: {e}")
196192

197193
def get_storage_args(self, storage_name):
198194
try:

vdirsyncer/cli/discover.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ async def collections_for_pair(
7474
" before synchronization.".format(pair.name)
7575
)
7676

77-
logger.info("Discovering collections for pair {}".format(pair.name))
77+
logger.info(f"Discovering collections for pair {pair.name}")
7878

7979
a_discovered = _DiscoverResult(pair.config_a, connector=connector)
8080
b_discovered = _DiscoverResult(pair.config_b, connector=connector)

vdirsyncer/cli/fetchparams.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ def expand_fetch_params(config):
3030
@synchronized()
3131
def _fetch_value(opts, key):
3232
if not isinstance(opts, list):
33-
raise ValueError(
34-
"Invalid value for {}: Expected a list, found {!r}.".format(key, opts)
35-
)
33+
raise ValueError(f"Invalid value for {key}: Expected a list, found {opts!r}.")
3634
if not opts:
3735
raise ValueError("Expected list of length > 0.")
3836

@@ -58,7 +56,7 @@ def _fetch_value(opts, key):
5856
except KeyError:
5957
raise exceptions.UserError(f"Unknown strategy: {strategy}")
6058

61-
logger.debug("Fetching value for {} with {} strategy.".format(key, strategy))
59+
logger.debug(f"Fetching value for {key} with {strategy} strategy.")
6260
try:
6361
rv = strategy_fn(*opts[1:])
6462
except (click.Abort, KeyboardInterrupt) as e:

vdirsyncer/cli/tasks.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ async def discover_collections(pair, **kwargs):
9393
collections = [c for c, (a, b) in rv]
9494
if collections == [None]:
9595
collections = None
96-
cli_logger.info(
97-
"Saved for {}: collections = {}".format(pair.name, json.dumps(collections))
98-
)
96+
cli_logger.info(f"Saved for {pair.name}: collections = {json.dumps(collections)}")
9997

10098

10199
async def repair_collection(

0 commit comments

Comments
 (0)