浏览代码

Merge pull request #9142 from ThomasWaldmann/py310-improvements-master

refactor: update type hints to use Python 3.10+ syntax
TW 1 月之前
父节点
当前提交
c9484a9f3e
共有 6 个文件被更改,包括 18 次插入20 次删除
  1. 1 1
      src/borg/chunkers/failing.py
  2. 3 3
      src/borg/chunkers/fixed.py
  3. 3 3
      src/borg/hashindex.pyi
  4. 0 1
      src/borg/helpers/__init__.py
  5. 10 10
      src/borg/item.pyi
  6. 1 2
      src/borg/legacyrepository.py

+ 1 - 1
src/borg/chunkers/failing.py

@@ -26,7 +26,7 @@ class ChunkerFailing:
         self.count = 0
         self.chunking_time = 0.0  # not updated, just provided so that caller does not crash
 
-    def chunkify(self, fd: BinaryIO = None, fh: int = -1) -> Iterator:
+    def chunkify(self, fd: BinaryIO | None = None, fh: int = -1) -> Iterator:
         """
         Cut a file into chunks.
 

+ 3 - 3
src/borg/chunkers/fixed.py

@@ -1,4 +1,4 @@
-from typing import List, Iterator, BinaryIO
+from typing import Iterator, BinaryIO
 
 API_VERSION = "1.2_01"
 
@@ -33,10 +33,10 @@ class ChunkerFixed:
         self.header_size = header_size
         self.chunking_time = 0.0  # likely will stay close to zero - not much to do here.
         self.reader_block_size = 1024 * 1024
-        self.reader: FileReader = None
+        self.reader: FileReader | None = None
         self.sparse = sparse
 
-    def chunkify(self, fd: BinaryIO = None, fh: int = -1, fmap: List = None) -> Iterator:
+    def chunkify(self, fd: BinaryIO | None = None, fh: int = -1, fmap: list | None = None) -> Iterator:
         """
         Cut a file into chunks.
 

+ 3 - 3
src/borg/hashindex.pyi

@@ -1,14 +1,14 @@
-from typing import NamedTuple, Tuple, Type, Union, IO, Iterator, Any
+from typing import NamedTuple, Tuple, Type, IO, Iterator, Any
 
 API_VERSION: str
 
-PATH_OR_FILE = Union[str, IO]
+PATH_OR_FILE = str | IO
 
 class ChunkIndexEntry(NamedTuple):
     flags: int
     size: int
 
-CIE = Union[Tuple[int, int], Type[ChunkIndexEntry]]
+CIE = Tuple[int, int] | Type[ChunkIndexEntry]
 
 class ChunkIndex:
     F_NONE: int

+ 0 - 1
src/borg/helpers/__init__.py

@@ -7,7 +7,6 @@ package, which are imported here for compatibility.
 
 import os
 import logging
-from typing import List
 from collections import namedtuple
 
 from ..constants import *  # NOQA

+ 10 - 10
src/borg/item.pyi

@@ -1,4 +1,4 @@
-from typing import Set, NamedTuple, Tuple, Mapping, Dict, List, Iterator, Callable, Any, Optional
+from typing import Set, NamedTuple, Tuple, Mapping, Dict, List, Iterator, Callable, Any
 
 from .helpers import StableDict
 
@@ -258,7 +258,7 @@ class ManifestItem(PropDict):
 class DiffChange:
     diff_type: str
     diff_data: Dict[str, Any]
-    def __init__(self, diff_type: str, diff_data: Optional[Dict[str, Any]] = ...) -> None: ...
+    def __init__(self, diff_type: str, diff_data: Dict[str, Any] | None = ...) -> None: ...
     def to_dict(self) -> Dict[str, Any]: ...
 
 class ItemDiff:
@@ -281,14 +281,14 @@ class ItemDiff:
     ) -> None: ...
     def changes(self) -> Dict[str, DiffChange]: ...
     def equal(self, content_only: bool = ...) -> bool: ...
-    def content(self) -> Optional[DiffChange]: ...
-    def ctime(self) -> Optional[DiffChange]: ...
-    def mtime(self) -> Optional[DiffChange]: ...
-    def mode(self) -> Optional[DiffChange]: ...
-    def type(self) -> Optional[DiffChange]: ...
-    def owner(self) -> Optional[DiffChange]: ...
-    def user(self) -> Optional[DiffChange]: ...
-    def group(self) -> Optional[DiffChange]: ...
+    def content(self) -> DiffChange | None: ...
+    def ctime(self) -> DiffChange | None: ...
+    def mtime(self) -> DiffChange | None: ...
+    def mode(self) -> DiffChange | None: ...
+    def type(self) -> DiffChange | None: ...
+    def owner(self) -> DiffChange | None: ...
+    def user(self) -> DiffChange | None: ...
+    def group(self) -> DiffChange | None: ...
 
 def chunk_content_equal(chunks_a: Iterator, chunks_b: Iterator) -> bool: ...
 

+ 1 - 2
src/borg/legacyrepository.py

@@ -9,7 +9,6 @@ from collections import defaultdict
 from configparser import ConfigParser
 from functools import partial
 from itertools import islice
-from typing import DefaultDict
 from collections.abc import Callable
 
 from .constants import *  # NOQA
@@ -48,7 +47,7 @@ TAG_PUT2 = 3
 # may not be able to handle the new tags.
 MAX_TAG_ID = 15
 
-FreeSpace: Callable[[], DefaultDict] = partial(defaultdict, int)
+FreeSpace: Callable[[], defaultdict] = partial(defaultdict, int)
 
 
 def header_size(tag):