Skip to content

Commit 39b847a

Browse files
Merge pull request #8859 from ThomasWaldmann/pyupgrade-py310-plus
pyupgrade --py310-plus ./**/*.py
2 parents 38a328b + c7765ad commit 39b847a

17 files changed

+45
-51
lines changed

scripts/errorlist.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
def subclasses(cls):
1313
direct_subclasses = cls.__subclasses__()
14-
return set(direct_subclasses) | set(s for c in direct_subclasses for s in subclasses(c))
14+
return set(direct_subclasses) | {s for c in direct_subclasses for s in subclasses(c)}
1515

1616

1717
# 0, 1, 2 are used for success, generic warning, generic error

src/borg/archive.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from getpass import getuser
1313
from io import BytesIO
1414
from itertools import groupby, zip_longest
15-
from typing import Iterator
15+
from collections.abc import Iterator
1616
from shutil import get_terminal_size
1717

1818
from .platformflags import is_win32

src/borg/archiver/compact_cmd.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import os
3-
from typing import Tuple, Set
43

54
from ._common import with_repository
65
from ..archive import Archive
@@ -101,7 +100,7 @@ def cleanup_files_cache(self):
101100
logger.warning(f"Could not access cache directory: {e}")
102101
return
103102

104-
used_files_cache_names = set(files_cache_name(series_name) for series_name in existing_series)
103+
used_files_cache_names = {files_cache_name(series_name) for series_name in existing_series}
105104
unused_files_cache_names = files_cache_names - used_files_cache_names
106105

107106
for cache_filename in unused_files_cache_names:
@@ -112,7 +111,7 @@ def cleanup_files_cache(self):
112111
logger.warning(f"Could not access cache file: {e}")
113112
logger.info(f"Removed {len(unused_files_cache_names)} unused files cache files.")
114113

115-
def analyze_archives(self) -> Tuple[Set, int, int, int]:
114+
def analyze_archives(self) -> tuple[set, int, int, int]:
116115
"""Iterate over all items in all archives, create the dicts id -> size of all used chunks."""
117116

118117
def use_it(id):

src/borg/archiver/diff_cmd.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ def print_json_output(diff):
4848
)
4949

5050
def print_text_output(diff, formatter):
51-
actual_changes = dict(
52-
(name, change)
51+
actual_changes = {
52+
name: change
5353
for name, change in diff.changes().items()
5454
if actual_change(change) and (not args.content_only or (name not in DiffFormatter.METADATA))
55-
)
55+
}
5656
diff._changes = actual_changes
5757
res: str = formatter.format_item(diff)
5858
if res.strip():

src/borg/archiver/tag_cmd.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def do_tag(self, args, repository, manifest, cache):
1818

1919
def tags_set(tags):
2020
"""return a set of tags, removing empty tags"""
21-
return set(tag for tag in tags if tag)
21+
return {tag for tag in tags if tag}
2222

2323
if args.name:
2424
archive_infos = [manifest.archives.get_one([args.name])]

src/borg/conftest.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import os
2-
from typing import Optional, List
32

43
import pytest
54

@@ -65,19 +64,19 @@ def set_env_variables():
6564
class ArchiverSetup:
6665
EXE: str = None # python source based
6766
FORK_DEFAULT = False
68-
BORG_EXES: List[str] = []
67+
BORG_EXES: list[str] = []
6968

7069
def __init__(self):
7170
self.archiver = None
72-
self.tmpdir: Optional[str] = None
73-
self.repository_path: Optional[str] = None
74-
self.repository_location: Optional[str] = None
75-
self.input_path: Optional[str] = None
76-
self.output_path: Optional[str] = None
77-
self.keys_path: Optional[str] = None
78-
self.cache_path: Optional[str] = None
79-
self.exclude_file_path: Optional[str] = None
80-
self.patterns_file_path: Optional[str] = None
71+
self.tmpdir: str | None = None
72+
self.repository_path: str | None = None
73+
self.repository_location: str | None = None
74+
self.input_path: str | None = None
75+
self.output_path: str | None = None
76+
self.keys_path: str | None = None
77+
self.cache_path: str | None = None
78+
self.exclude_file_path: str | None = None
79+
self.patterns_file_path: str | None = None
8180

8281
def get_kind(self) -> str:
8382
if self.repository_location.startswith("ssh://__testsuite__"):

src/borg/crypto/file_integrity.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import json
44
import os
55
from hmac import compare_digest
6-
from typing import Callable
6+
from collections.abc import Callable
77

88
from ..helpers import IntegrityError
99
from ..logger import create_logger

src/borg/crypto/key.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44
import textwrap
55
from hashlib import sha256, pbkdf2_hmac
6-
from typing import Literal, Callable, ClassVar
6+
from typing import Literal, ClassVar
7+
from collections.abc import Callable
78

89
from ..logger import create_logger
910

@@ -563,7 +564,7 @@ def sanity_check(self, filename, id):
563564
raise KeyfileMismatchError(self.repository._location.canonical_path(), filename)
564565
# we get here if it really looks like a borg key for this repo,
565566
# do some more checks that are close to how borg reads/parses the key.
566-
with open(filename, "r") as fd:
567+
with open(filename) as fd:
567568
lines = fd.readlines()
568569
if len(lines) < 2:
569570
logger.warning(f"borg key sanity check: expected 2+ lines total. [{filename}]")

src/borg/helpers/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"""
6868
The global warnings_list variable is used to collect warning_info elements while borg is running.
6969
"""
70-
_warnings_list: List[warning_info] = []
70+
_warnings_list: list[warning_info] = []
7171

7272

7373
def add_warning(msg, *args, **kwargs):
@@ -159,7 +159,7 @@ def get_ec(ec=None):
159159
# we do not have any warnings in warnings list, return success exit code
160160
return _exit_code
161161
# looks like we have some warning(s)
162-
rcs = sorted(set(w_info.wc for w_info in _warnings_list))
162+
rcs = sorted({w_info.wc for w_info in _warnings_list})
163163
logger.debug(f"rcs: {rcs!r}")
164164
if len(rcs) == 1:
165165
# easy: there was only one kind of warning, so we can be specific

src/borg/helpers/parseformat.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import shlex
1111
import stat
1212
import uuid
13-
from typing import Dict, Set, Tuple, ClassVar, Any, TYPE_CHECKING, Literal
13+
from typing import ClassVar, Any, TYPE_CHECKING, Literal
1414
from collections import OrderedDict
1515
from datetime import datetime, timezone
1616
from functools import partial
@@ -646,8 +646,8 @@ def archivename_validator(text):
646646

647647
class BaseFormatter(metaclass=abc.ABCMeta):
648648
format: str
649-
static_data: Dict[str, Any]
650-
FIXED_KEYS: ClassVar[Dict[str, str]] = {
649+
static_data: dict[str, Any]
650+
FIXED_KEYS: ClassVar[dict[str, str]] = {
651651
# Formatting aids
652652
"LF": "\n",
653653
"SPACE": " ",
@@ -657,7 +657,7 @@ class BaseFormatter(metaclass=abc.ABCMeta):
657657
"NEWLINE": "\n",
658658
"NL": "\n", # \n is automatically converted to os.linesep on write
659659
}
660-
KEY_DESCRIPTIONS: ClassVar[Dict[str, str]] = {
660+
KEY_DESCRIPTIONS: ClassVar[dict[str, str]] = {
661661
"NEWLINE": "OS dependent line separator",
662662
"NL": "alias of NEWLINE",
663663
"NUL": "NUL character for creating print0 / xargs -0 like output",
@@ -666,9 +666,9 @@ class BaseFormatter(metaclass=abc.ABCMeta):
666666
"CR": "carriage return character",
667667
"LF": "line feed character",
668668
}
669-
KEY_GROUPS: ClassVar[Tuple[Tuple[str, ...], ...]] = (("NEWLINE", "NL", "NUL", "SPACE", "TAB", "CR", "LF"),)
669+
KEY_GROUPS: ClassVar[tuple[tuple[str, ...], ...]] = (("NEWLINE", "NL", "NUL", "SPACE", "TAB", "CR", "LF"),)
670670

671-
def __init__(self, format: str, static: Dict[str, Any]) -> None:
671+
def __init__(self, format: str, static: dict[str, Any]) -> None:
672672
self.format = partial_format(format, static)
673673
self.static_data = static
674674

@@ -685,7 +685,7 @@ def format_item(self, item, jsonline=False, sort=False):
685685
@classmethod
686686
def keys_help(cls):
687687
help = []
688-
keys: Set[str] = set()
688+
keys: set[str] = set()
689689
keys.update(cls.KEY_DESCRIPTIONS.keys())
690690
keys.update(key for group in cls.KEY_GROUPS for key in group)
691691

0 commit comments

Comments
 (0)