Skip to content

Commit

Permalink
Fix more ruff issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Mar 3, 2025
1 parent 260d5e8 commit c212340
Show file tree
Hide file tree
Showing 93 changed files with 350 additions and 381 deletions.
3 changes: 2 additions & 1 deletion breezy/archive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

"""Export trees to tarballs, zipfiles, etc."""

from typing import Iterator, cast
from collections.abc import Iterator
from typing import cast

from .. import errors, registry

Expand Down
24 changes: 12 additions & 12 deletions breezy/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

__docformat__ = "google"

from typing import TYPE_CHECKING, Dict, List, Optional, TextIO, Tuple, Union, cast
from typing import TYPE_CHECKING, Optional, TextIO, Union, cast

from .lazy_import import lazy_import

Expand Down Expand Up @@ -95,7 +95,7 @@ class Branch(ControlComponent):

_format: "BranchFormat"

_last_revision_info_cache: Optional[Tuple[int, RevisionID]]
_last_revision_info_cache: Optional[tuple[int, RevisionID]]

repository: repository.Repository

Expand All @@ -105,12 +105,12 @@ class Branch(ControlComponent):
def user_transport(self) -> Transport:
return self.controldir.user_transport

def __init__(self, possible_transports: Optional[List[Transport]] = None) -> None:
def __init__(self, possible_transports: Optional[list[Transport]] = None) -> None:
self.tags = self._format.make_tags(self)
self._revision_history_cache = None
self._revision_id_to_revno_cache = None
self._partial_revision_id_to_revno_cache: Dict[RevisionID, int] = {}
self._partial_revision_history_cache: List[RevisionID] = []
self._partial_revision_id_to_revno_cache: dict[RevisionID, int] = {}
self._partial_revision_history_cache: list[RevisionID] = []
self._last_revision_info_cache = None
self._master_branch_cache = None
self._merge_sorted_revisions_cache = None
Expand Down Expand Up @@ -769,7 +769,7 @@ def get_commit_builder(
)

def get_master_branch(
self, possible_transports: Optional[List[Transport]] = None
self, possible_transports: Optional[list[Transport]] = None
) -> Optional["Branch"]:
"""Return the branch we are bound to.
Expand Down Expand Up @@ -905,7 +905,7 @@ def _gen_revision_history(self):
"""
raise NotImplementedError(self._gen_revision_history)

def _revision_history(self) -> List[RevisionID]:
def _revision_history(self) -> list[RevisionID]:
if "evil" in debug.debug_flags:
mutter_callsite(3, "revision_history scales with history.")
if self._revision_history_cache is not None:
Expand All @@ -931,7 +931,7 @@ def last_revision(self) -> RevisionID:
"""Return last revision id, or NULL_REVISION."""
return self.last_revision_info()[1]

def last_revision_info(self) -> Tuple[int, RevisionID]:
def last_revision_info(self) -> tuple[int, RevisionID]:
"""Return information about the last revision.
Returns: A tuple (revno, revision_id).
Expand Down Expand Up @@ -976,7 +976,7 @@ def revision_id_to_revno(self, revision_id: RevisionID) -> int:
raise errors.NoSuchRevision(self, revision_id) from exc

def get_rev_id(
self, revno: int, history: Optional[List[RevisionID]] = None
self, revno: int, history: Optional[list[RevisionID]] = None
) -> RevisionID:
"""Find the revision id of the specified revno."""
with self.lock_read():
Expand All @@ -998,7 +998,7 @@ def pull(
*,
overwrite: bool = False,
stop_revision: Optional[RevisionID] = None,
possible_transports: Optional[List[Transport]] = None,
possible_transports: Optional[list[Transport]] = None,
**kwargs,
) -> "PullResult":
"""Mirror source into this branch.
Expand Down Expand Up @@ -2021,7 +2021,7 @@ class PullResult(_Result):
master_branch: Branch
local_branch: Optional[Branch]
target_branch: Branch
tag_conflicts: List["TagConflict"]
tag_conflicts: list["TagConflict"]
tag_updates: "TagUpdates"

def report(self, to_file: TextIO) -> None:
Expand Down Expand Up @@ -2153,7 +2153,7 @@ def pull(
self,
overwrite: bool = False,
stop_revision: Optional[RevisionID] = None,
possible_transports: Optional[List[Transport]] = None,
possible_transports: Optional[list[Transport]] = None,
local: bool = False,
tag_selector=None,
) -> PullResult:
Expand Down
3 changes: 2 additions & 1 deletion breezy/bzr/_rio_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
"""Python implementation of _read_stanza_*."""

import re
from typing import Iterator, Optional
from collections.abc import Iterator
from typing import Optional

from .rio import Stanza

Expand Down
5 changes: 1 addition & 4 deletions breezy/bzr/_static_tuple_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@
strings.
"""

from typing import Dict


class StaticTuple(tuple):
"""A static type, similar to a tuple of strings."""

Expand Down Expand Up @@ -82,4 +79,4 @@ def from_sequence(seq):
# the _empty_tuple singleton has been created yet or not.
_empty_tuple = None
_empty_tuple = StaticTuple()
_interned_tuples: Dict[StaticTuple, StaticTuple] = {}
_interned_tuples: dict[StaticTuple, StaticTuple] = {}
4 changes: 2 additions & 2 deletions breezy/bzr/bzrdir.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

import contextlib
import sys
from typing import Set, cast
from typing import cast

from ..lazy_import import lazy_import

Expand Down Expand Up @@ -1226,7 +1226,7 @@ class BzrFormat:
:ivar features: Dictionary mapping feature names to their necessity
"""

_present_features: Set[str] = set()
_present_features: set[str] = set()

def __init__(self):
self.features = {}
Expand Down
3 changes: 1 addition & 2 deletions breezy/bzr/groupcompress.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import time
import zlib
from typing import Type

from ..lazy_import import lazy_import

Expand Down Expand Up @@ -2339,7 +2338,7 @@ def scan_unvalidated_index(self, graph_index):
key_dependencies.add_references(node[1], node[3][0])


GroupCompressor: Type[_CommonGroupCompressor]
GroupCompressor: type[_CommonGroupCompressor]


from ._groupcompress_py import (
Expand Down
8 changes: 3 additions & 5 deletions breezy/bzr/knitrepo.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from typing import Type

from ..lazy_import import lazy_import

lazy_import(
Expand Down Expand Up @@ -115,7 +113,7 @@ class KnitRepository(MetaDirVersionedFileRepository):
# them to None ensures that if the constructor is changed to not initialize
# them, or a subclass fails to call the constructor, that an error will
# occur rather than the system working but generating incorrect data.
_commit_builder_class: Type[VersionedFileCommitBuilder]
_commit_builder_class: type[VersionedFileCommitBuilder]
_serializer: Serializer

def __init__(
Expand Down Expand Up @@ -228,11 +226,11 @@ class RepositoryFormatKnit(MetaDirVersionedFileRepositoryFormat):

# Set this attribute in derived classes to control the repository class
# created by open and initialize.
repository_class: Type[Repository]
repository_class: type[Repository]
# Set this attribute in derived classes to control the
# _commit_builder_class that the repository objects will have passed to
# their constructor.
_commit_builder_class: Type[VersionedFileCommitBuilder]
_commit_builder_class: type[VersionedFileCommitBuilder]
# Set this attribute in derived clases to control the _serializer that the
# repository objects will have passed to their constructor.

Expand Down
19 changes: 9 additions & 10 deletions breezy/bzr/pack_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import re
import sys
from typing import Type

from ..lazy_import import lazy_import

Expand Down Expand Up @@ -922,10 +921,10 @@ class RepositoryPackCollection:
:ivar _names: map of {pack_name: (index_size,)}
"""

pack_factory: Type[NewPack]
resumed_pack_factory: Type[ResumedPack]
normal_packer_class: Type[Packer]
optimising_packer_class: Type[Packer]
pack_factory: type[NewPack]
resumed_pack_factory: type[ResumedPack]
normal_packer_class: type[Packer]
optimising_packer_class: type[Packer]

def __init__(
self,
Expand Down Expand Up @@ -1884,7 +1883,7 @@ class PackRepository(MetaDirVersionedFileRepository):
# them to None ensures that if the constructor is changed to not initialize
# them, or a subclass fails to call the constructor, that an error will
# occur rather than the system working but generating incorrect data.
_commit_builder_class: Type[VersionedFileCommitBuilder]
_commit_builder_class: type[VersionedFileCommitBuilder]
_serializer: Serializer

def __init__(
Expand Down Expand Up @@ -2080,11 +2079,11 @@ class RepositoryFormatPack(MetaDirVersionedFileRepositoryFormat):

# Set this attribute in derived classes to control the repository class
# created by open and initialize.
repository_class: Type[PackRepository]
repository_class: type[PackRepository]
# Set this attribute in derived classes to control the
# _commit_builder_class that the repository objects will have passed to
# their constructor.
_commit_builder_class: Type[VersionedFileCommitBuilder]
_commit_builder_class: type[VersionedFileCommitBuilder]
# Set this attribute in derived clases to control the _serializer that the
# repository objects will have passed to their constructor.
_serializer: Serializer
Expand All @@ -2095,8 +2094,8 @@ class RepositoryFormatPack(MetaDirVersionedFileRepositoryFormat):
# Most pack formats do not use chk lookups.
supports_chks: bool = False
# What index classes to use
index_builder_class: Type[_mod_index.GraphIndexBuilder]
index_class: Type[object]
index_builder_class: type[_mod_index.GraphIndexBuilder]
index_class: type[object]
_fetch_uses_deltas: bool = True
fast_deltas: bool = False
supports_funky_characters: bool = True
Expand Down
4 changes: 2 additions & 2 deletions breezy/bzr/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import os
import re
import zlib
from typing import Callable, List, Optional
from typing import Callable, Optional

import fastbencode as bencode

Expand Down Expand Up @@ -3724,7 +3724,7 @@ def __init__(
format=None,
setup_stacking: bool = True,
name: Optional[str] = None,
possible_transports: Optional[List[_mod_transport.Transport]] = None,
possible_transports: Optional[list[_mod_transport.Transport]] = None,
):
"""Create a RemoteBranch instance.
Expand Down
8 changes: 4 additions & 4 deletions breezy/bzr/tests/test_smart_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import threading
import time
from io import BytesIO
from typing import Optional, Type
from typing import Optional

from testtools.matchers import DocTestMatches

Expand Down Expand Up @@ -1963,9 +1963,9 @@ class TestSmartProtocol(tests.TestCase):
"""

request_encoder: object
response_decoder: Type[protocol._StatefulDecoder]
server_protocol_class: Type[protocol.SmartProtocolBase]
client_protocol_class: Optional[Type[protocol.SmartProtocolBase]] = None
response_decoder: type[protocol._StatefulDecoder]
server_protocol_class: type[protocol.SmartProtocolBase]
client_protocol_class: Optional[type[protocol.SmartProtocolBase]] = None

def make_client_protocol_and_output(self, input_bytes=None):
# This is very similar to
Expand Down
4 changes: 2 additions & 2 deletions breezy/bzr/versionedfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import struct
from copy import copy
from io import BytesIO
from typing import Any, Tuple
from typing import Any
from zlib import adler32

from ..lazy_import import lazy_import
Expand Down Expand Up @@ -49,7 +49,7 @@
from ..textmerge import TextMerge
from . import index

adapter_registry = Registry[Tuple[str, str], Any]()
adapter_registry = Registry[tuple[str, str], Any]()
adapter_registry.register_lazy(
("knit-annotated-delta-gz", "knit-delta-gz"),
"breezy.bzr.knit",
Expand Down
4 changes: 2 additions & 2 deletions breezy/bzr/xml8.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from typing import List, Optional
from typing import Optional

from .. import lazy_regex, trace
from .. import revision as _mod_revision
Expand Down Expand Up @@ -63,7 +63,7 @@ class Serializer_v8(XMLSerializer):
Its revision format number matches its inventory number.
"""

__slots__: List[str] = []
__slots__: list[str] = []

root_id: Optional[bytes] = None
support_altered_by_hack = True
Expand Down
4 changes: 2 additions & 2 deletions breezy/bzr/xml_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
]

import re
from typing import Dict, Union
from typing import Union
from xml.etree.ElementTree import (
Element,
ElementTree,
Expand Down Expand Up @@ -201,7 +201,7 @@ def _utf8_escape_replace(match, _map=_xml_escape_map):
)


_to_escaped_map: Dict[Union[bytes, str], str] = {}
_to_escaped_map: dict[Union[bytes, str], str] = {}


def encode_and_escape(unicode_or_utf8_str, _map=_to_escaped_map):
Expand Down
4 changes: 2 additions & 2 deletions breezy/bzr_distutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from distutils.core import Command
from distutils.dep_util import newer
from distutils.spawn import find_executable
from typing import List, Optional
from typing import Optional


class build_mo(Command):
Expand All @@ -49,7 +49,7 @@ class build_mo(Command):
source_dir: Optional[str]
build_dir: Optional[str]
output_base: Optional[str]
lang: Optional[List[str]]
lang: Optional[list[str]]

def initialize_options(self) -> None:
self.build_dir = None
Expand Down
5 changes: 2 additions & 3 deletions breezy/cache_utf8.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

from codecs import utf_8_decode as _utf8_decode
from codecs import utf_8_encode as _utf8_encode
from typing import Dict


def _utf8_decode_with_None(bytestring, _utf8_decode=_utf8_decode):
Expand All @@ -39,8 +38,8 @@ def _utf8_decode_with_None(bytestring, _utf8_decode=_utf8_decode):
# Map revisions from and to utf8 encoding
# Whenever we do an encode/decode operation, we save the result, so that
# we don't have to do it again.
_unicode_to_utf8_map: Dict[str, bytes] = {}
_utf8_to_unicode_map: Dict[bytes, str] = {}
_unicode_to_utf8_map: dict[str, bytes] = {}
_utf8_to_unicode_map: dict[bytes, str] = {}


def encode(
Expand Down
Loading

0 comments on commit c212340

Please sign in to comment.