Merge pull request #9142 from ThomasWaldmann/py310-improvements-master
Some checks failed
Lint / lint (push) Has been cancelled
CI / lint (push) Has been cancelled
CI / security (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
CI / asan_ubsan (push) Has been cancelled
CI / posix_tests (push) Has been cancelled
CI / windows_tests (push) Has been cancelled

refactor: update type hints to use Python 3.10+ syntax
This commit is contained in:
TW 2025-11-03 23:44:38 +01:00 committed by GitHub
commit c9484a9f3e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 18 additions and 20 deletions

View file

@ -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.

View file

@ -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.

View file

@ -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

View file

@ -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

View file

@ -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: ...

View file

@ -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):