From 4a3f1761b66978566838ae6898c53d7e09ef9b5c Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Thu, 29 Oct 2026 08:16:56 +0000 Subject: [PATCH 1/4] chore: Drop support for python3.9 and update pins to minimum for python3.10 --- .github/workflows/testing.yml | 4 +--- kazoo/handlers/eventlet.py | 9 +++------ kazoo/handlers/utils.py | 2 +- pyproject.toml | 25 ++++++++++++------------- 4 files changed, 17 insertions(+), 23 deletions(-) diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml index cae7955e..d5bc0df1 100644 --- a/.github/workflows/testing.yml +++ b/.github/workflows/testing.yml @@ -48,7 +48,7 @@ jobs: strategy: fail-fast: false matrix: - python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "pypy-3.11-v7.3.21"] + python-version: ["3.10", "3.11", "3.12", "3.13", "3.14", "pypy-3.11-v7.3.21"] # Friendly note: If you change the minimum zk-version here, update it in # ensure-zookeeper-env.sh. Additionally, if you need to change the way that # zookeeper is installed, do it THERE. Not in the 'test with tox' step here. @@ -56,8 +56,6 @@ jobs: # things to work properly before submitting a PR. zk-version: ["3.6.4", "3.7.2", "3.8.3", "3.9.1"] include: - - python-version: "3.9" - tox-env: py39 - python-version: "3.10" tox-env: py310 - python-version: "3.11" diff --git a/kazoo/handlers/eventlet.py b/kazoo/handlers/eventlet.py index c6f01d11..255d8b05 100644 --- a/kazoo/handlers/eventlet.py +++ b/kazoo/handlers/eventlet.py @@ -107,11 +107,8 @@ def __init__(self) -> None: self.completion_queue = ( self.queue_impl() # type: ignore[no-untyped-call] ) - self._workers: list[ # type: ignore[name-defined] - tuple[ - eventlet.GreenThread, - green_queue.LightQueue, - ] + self._workers: list[ + tuple[eventlet.greenthread.GreenThread, green_queue.LightQueue] ] = [] self._started = False @@ -177,7 +174,7 @@ def stop(self) -> None: while self._workers: w, q = self._workers.pop() q.put(_STOP) # type: ignore[no-untyped-call] - w.wait() + w.wait() # type: ignore[no-untyped-call] self._started = False atexit.unregister(self.stop) diff --git a/kazoo/handlers/utils.py b/kazoo/handlers/utils.py index c7741087..bc420dc0 100644 --- a/kazoo/handlers/utils.py +++ b/kazoo/handlers/utils.py @@ -50,7 +50,7 @@ def __init__( self._condition = condition_factory() self._callbacks: list[CallbackFunc] = [] self._timeout_factory = timeout_factory - self.value = None + self.value: Any = None def ready(self) -> bool: """Return true if and only if it holds a value or an diff --git a/pyproject.toml b/pyproject.toml index 9455bf32..fa9bb128 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,7 +8,7 @@ requires = [ name = "kazoo" dynamic = ["version", "readme"] description = "Higher Level Zookeeper Client" -requires-python = ">=3.9" +requires-python = ">=3.10" license = {text = "Apache 2.0"} authors = [ {name = "Kazoo team", email = "python-zk@googlegroups.com"}, @@ -21,7 +21,6 @@ classifiers = [ "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", "Programming Language :: Python :: 3.12", @@ -53,26 +52,26 @@ ruff = [ ] test-extras = [ "cryptography==50.0.1", - "objgraph==3.6.2", + "objgraph==3.7.0", "pyjks==20.0.0", - "unittest-parametrize==1.8.0", + "unittest-parametrize==1.9.0", ] pytest = [ - "pytest==8.4.2", + "pytest==9.2.0", ] test = [ - "coverage==7.10.7", + "coverage==7.16.2", {include-group = "pytest"}, "pytest-cov==7.1.0", - "pytest-timeout==2.4.0", + "pytest-timeout==2.5.0", {include-group = "test-extras"}, ] typing = [ - "mypy==1.19.1", - "types-gevent==25.9.0.20251228", - "types-mock==5.2.0.20250924", - "types-objgraph==3.6.0.20240907", - "types-pyjks==20.0.0.20240310", + "mypy==2.4.1", + "types-gevent==26.9.0.20261006", + "types-mock==5.2.0.20260518", + "types-objgraph==3.7.0.20261018", + "types-pyjks==20.0.0.20260724", ] mypy = [ {include-group = "typing"}, @@ -95,7 +94,7 @@ readme = {file = ["README.md", "CHANGES.md", "CONTRIBUTING.md"], content-type = [tool.ruff] line-length = 79 -target-version = "py39" +target-version = "py310" builtins = ["_"] exclude = [ "docs/conf.py", From 2ff3656e34689377d5a551af4775d172f54f73d4 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Thu, 29 Oct 2026 22:39:18 +0000 Subject: [PATCH 2/4] chore: Reenable unused-ignore in mypy and fixed unused suppressions --- kazoo/client.py | 2 +- kazoo/handlers/gevent.py | 16 ++++++++-------- kazoo/protocol/connection.py | 14 ++++---------- kazoo/recipe/cache.py | 2 +- kazoo/recipe/watchers.py | 4 ++-- kazoo/tests/test_counter.py | 6 ++---- kazoo/tests/test_sasl.py | 2 +- kazoo/tests/test_threading_handler.py | 4 +--- pyproject.toml | 5 ----- 9 files changed, 20 insertions(+), 35 deletions(-) diff --git a/kazoo/client.py b/kazoo/client.py index 4877f358..6f1a1c0e 100644 --- a/kazoo/client.py +++ b/kazoo/client.py @@ -1279,7 +1279,7 @@ def do_create() -> None: # above ensures that if acl is None, it gets set to # OPEN_ACL_UNSAFE, so we ignore the type error here. # behaves differently in python3.8 and python3.14, sigh. - acl, # type: ignore[arg-type] + acl, flags, trailing=sequence, include_data=include_data, diff --git a/kazoo/handlers/gevent.py b/kazoo/handlers/gevent.py index 2f782fa2..e4f146f5 100644 --- a/kazoo/handlers/gevent.py +++ b/kazoo/handlers/gevent.py @@ -15,14 +15,14 @@ # We don't want to force the user to install gevent, so we need to handle the # case where it's not available, but there should be a cleaner we of doing this # than by importing all of gevent and ignoring all the import errors. -import gevent # type: ignore[import] -from gevent import socket # type: ignore[import] -import gevent.event # type: ignore[import] -import gevent.queue # type: ignore[import] - -import gevent.thread # type: ignore[import] -import gevent.selectors # type: ignore[import] -from gevent.lock import Semaphore, RLock # type: ignore[import] +import gevent +from gevent import socket +import gevent.event +import gevent.queue + +import gevent.thread +import gevent.selectors +from gevent.lock import Semaphore, RLock if TYPE_CHECKING: from kazoo.interfaces import FdLike, Lockable, Socket diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py index d35952be..18df3daa 100644 --- a/kazoo/protocol/connection.py +++ b/kazoo/protocol/connection.py @@ -67,8 +67,8 @@ # FIXME This is NOT pretty, but we don't want to force users to have to # install puresasl. Can we avoid some of the type: ignore stuff? try: - import puresasl # type: ignore[import-untyped,import-not-found] - import puresasl.client # type: ignore[import-untyped,import-not-found] + import puresasl + import puresasl.client PURESASL_AVAILABLE = True except ImportError: @@ -667,17 +667,11 @@ def _expand_client_hosts(self) -> list[tuple[str, str, int]]: for rhost in socket.getaddrinfo( host, port, 0, 0, socket.IPPROTO_TCP ): - # FIXME These casts seem to be unnecessary on later - # versions of mypy/python host_ports.append( ( host, - cast( # type: ignore[redundant-cast] - "str", rhost[4][0] - ), - cast( # type: ignore[redundant-cast] - "int", rhost[4][1] - ), + cast("str", rhost[4][0]), + cast("int", rhost[4][1]), ) ) except socket.gaierror as e: diff --git a/kazoo/recipe/cache.py b/kazoo/recipe/cache.py index 107d6849..48b87680 100644 --- a/kazoo/recipe/cache.py +++ b/kazoo/recipe/cache.py @@ -236,7 +236,7 @@ def _in_background( result: IAsyncResult, ) -> None: ... - def _in_background( # type: ignore[misc] + def _in_background( self, func: Callable[..., Any], *args: Any, **kwargs: Any ) -> None: self._task_queue.put((func, args, kwargs)) diff --git a/kazoo/recipe/watchers.py b/kazoo/recipe/watchers.py index 2a504ee2..e13b9892 100644 --- a/kazoo/recipe/watchers.py +++ b/kazoo/recipe/watchers.py @@ -131,7 +131,7 @@ def __init__( "ignore_missing_node is now assumed to be True by default, and the " "event will be sent if the function can handle receiving it" ) - def __init__( # type: ignore[misc] + def __init__( self, client: KazooClient, path: str, @@ -140,7 +140,7 @@ def __init__( # type: ignore[misc] **kwargs: Any, ): ... - def __init__( # type: ignore[misc] + def __init__( self, client: KazooClient, path: str, diff --git a/kazoo/tests/test_counter.py b/kazoo/tests/test_counter.py index 7c95b18f..4085b1ca 100644 --- a/kazoo/tests/test_counter.py +++ b/kazoo/tests/test_counter.py @@ -54,13 +54,11 @@ def test_float_counter(self) -> None: def test_errors(self) -> None: counter = self._makeOne() with pytest.raises(TypeError): - counter.__add__(2.1) # type: ignore[arg-type] + counter.__add__(2.1) with pytest.raises(TypeError): counter.__add__(b"a") # type: ignore[operator] with pytest.raises(TypeError): - counter = self._makeOne( # type: ignore[arg-type] - default=0.0, support_curator=True - ) + counter = self._makeOne(default=0.0, support_curator=True) def test_pre_post_values(self) -> None: counter = self._makeOne() diff --git a/kazoo/tests/test_sasl.py b/kazoo/tests/test_sasl.py index 41177705..549d6cf5 100644 --- a/kazoo/tests/test_sasl.py +++ b/kazoo/tests/test_sasl.py @@ -117,7 +117,7 @@ def setUp(self) -> None: except ImportError: pytest.skip("PureSASL not available.") try: - import kerberos # type: ignore[import-not-found,import-untyped] + import kerberos # type: ignore[import-not-found] except ImportError: pytest.skip("Kerberos support not available.") if not os.environ.get("KRB5_TEST_ENV"): diff --git a/kazoo/tests/test_threading_handler.py b/kazoo/tests/test_threading_handler.py index f4ac5d43..108be66f 100644 --- a/kazoo/tests/test_threading_handler.py +++ b/kazoo/tests/test_threading_handler.py @@ -23,9 +23,7 @@ def _getAsync(self) -> Type[AsyncResult]: def test_proper_threading(self) -> None: h = self._makeOne() h.start() - # In Python 3.3 _Event is gone, before Event is function - event_class = getattr(threading, "_Event", threading.Event) - assert isinstance(h.event_object(), event_class) + assert isinstance(h.event_object(), threading.Event) def test_matching_async(self) -> None: h = self._makeOne() diff --git a/pyproject.toml b/pyproject.toml index fa9bb128..3390b1da 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -198,11 +198,6 @@ show_absolute_path = false warn_unused_configs = true verbosity = 0 -# This is a temporary workaround for the fact that mypy can -# produce different errors in 3.9 and 3.14, and I want to avoid code changes -# as much as possible. -disable_error_code = [ 'unused-ignore' ] - [[tool.mypy.overrides]] module = ["eventlet.*"] follow_untyped_imports = true From c02e7fcf59f8dbe88a81258ccf11936a7bba14bf Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Fri, 30 Oct 2026 07:13:58 +0000 Subject: [PATCH 3/4] style: Use python3.10 idioms (mostly typing) - enable ruff 'U' messages --- kazoo/client.py | 24 ++++++----------- kazoo/exceptions.py | 10 ++++---- kazoo/handlers/eventlet.py | 3 ++- kazoo/handlers/gevent.py | 4 ++- kazoo/handlers/threading.py | 4 ++- kazoo/handlers/utils.py | 4 ++- kazoo/interfaces.py | 15 ++++------- kazoo/protocol/connection.py | 25 +++++------------- kazoo/protocol/serialization.py | 12 +++++---- kazoo/protocol/states.py | 4 ++- kazoo/recipe/cache.py | 18 ++++--------- kazoo/recipe/counter.py | 4 +-- kazoo/recipe/election.py | 3 ++- kazoo/recipe/lease.py | 3 ++- kazoo/recipe/lock.py | 15 +++-------- kazoo/recipe/partitioner.py | 14 +++------- kazoo/recipe/party.py | 3 ++- kazoo/recipe/watchers.py | 37 ++++++++++----------------- kazoo/retry.py | 3 ++- kazoo/testing/harness.py | 3 ++- kazoo/tests/test_connection.py | 7 ++--- kazoo/tests/test_eventlet_handler.py | 7 ++--- kazoo/tests/test_gevent_handler.py | 10 ++++---- kazoo/tests/test_lock.py | 11 ++++---- kazoo/tests/test_retry.py | 2 +- kazoo/tests/test_sasl.py | 5 +--- kazoo/tests/test_threading_handler.py | 6 ++--- kazoo/tests/test_watchers.py | 4 +-- kazoo/tests/util.py | 5 ++-- pyproject.toml | 6 ++--- 30 files changed, 116 insertions(+), 155 deletions(-) diff --git a/kazoo/client.py b/kazoo/client.py index 6f1a1c0e..169defa4 100644 --- a/kazoo/client.py +++ b/kazoo/client.py @@ -13,16 +13,13 @@ cast, overload, Any, - Callable, - Deque, - Iterable, Literal, Optional, - Sequence, - Set, TypedDict, TYPE_CHECKING, ) +from collections.abc import Callable +from collections.abc import Iterable, Sequence from typing_extensions import ParamSpec, Unpack, deprecated from kazoo.exceptions import ( @@ -121,10 +118,10 @@ class LegacyRetryParams(TypedDict, total=False): # Signature for functions called by add_listener -ListenerFunc = Callable[[KazooState], Optional[bool]] +ListenerFunc = Callable[[KazooState], bool | None] # Signatures for get, get_children and exists watches -WatchFunc = Callable[[WatchedEvent], Optional[bool]] +WatchFunc = Callable[[WatchedEvent], bool | None] GenericArgs = ParamSpec("GenericArgs") @@ -369,10 +366,10 @@ def __init__( self._state: KeeperState = KeeperState.CLOSED self.state: KazooState = KazooState.LOST self.state_listeners: set[ListenerFunc] = set() - self._child_watchers: defaultdict[str, Set[WatchFunc]] = defaultdict( + self._child_watchers: defaultdict[str, set[WatchFunc]] = defaultdict( set ) - self._data_watchers: defaultdict[str, Set[WatchFunc]] = defaultdict( + self._data_watchers: defaultdict[str, set[WatchFunc]] = defaultdict( set ) self._reset() @@ -551,8 +548,8 @@ def _retry( def _reset(self) -> None: """Resets a variety of client states for a new connection.""" - self._queue: Deque[tuple[Any, IAsyncResult]] = deque() - self._pending: Deque[tuple[Any, IAsyncResult, int]] = deque() + self._queue: deque[tuple[Any, IAsyncResult]] = deque() + self._pending: deque[tuple[Any, IAsyncResult, int]] = deque() self._reset_watchers() self._reset_session() @@ -1274,11 +1271,6 @@ def do_create() -> None: result = self._create_async_inner( path, value, - # The way acl is constructed ends up confusing mypy, which - # thinks that acl can be None here, even though the code - # above ensures that if acl is None, it gets set to - # OPEN_ACL_UNSAFE, so we ignore the type error here. - # behaves differently in python3.8 and python3.14, sigh. acl, flags, trailing=sequence, diff --git a/kazoo/exceptions.py b/kazoo/exceptions.py index ae9341df..ede2f572 100644 --- a/kazoo/exceptions.py +++ b/kazoo/exceptions.py @@ -3,7 +3,7 @@ from __future__ import annotations from collections import defaultdict -from typing import Callable, Type +from collections.abc import Callable class KazooException(Exception): @@ -54,19 +54,19 @@ class SASLException(KazooException): """ -def _invalid_error_code() -> Type[ZookeeperError]: +def _invalid_error_code() -> type[ZookeeperError]: raise RuntimeError("Invalid error code") -EXCEPTIONS: defaultdict[int, Type[ZookeeperError]] = defaultdict( +EXCEPTIONS: defaultdict[int, type[ZookeeperError]] = defaultdict( _invalid_error_code ) def _zookeeper_exception( code: int, -) -> Callable[[Type[ZookeeperError]], Type[ZookeeperError]]: - def decorator(klass: Type[ZookeeperError]) -> Type[ZookeeperError]: +) -> Callable[[type[ZookeeperError]], type[ZookeeperError]]: + def decorator(klass: type[ZookeeperError]) -> type[ZookeeperError]: EXCEPTIONS[code] = klass # Unfortunately there is currently no good of doing the assignment here # in a way that type checkers would allow. It's a known problem (see diff --git a/kazoo/handlers/eventlet.py b/kazoo/handlers/eventlet.py index 255d8b05..a52d908d 100644 --- a/kazoo/handlers/eventlet.py +++ b/kazoo/handlers/eventlet.py @@ -6,7 +6,8 @@ import contextlib import logging -from typing import cast, Any, Generator, TYPE_CHECKING +from typing import cast, Any, TYPE_CHECKING +from collections.abc import Generator import eventlet from eventlet.green import socket as green_socket diff --git a/kazoo/handlers/gevent.py b/kazoo/handlers/gevent.py index e4f146f5..a998e548 100644 --- a/kazoo/handlers/gevent.py +++ b/kazoo/handlers/gevent.py @@ -5,7 +5,9 @@ import atexit import logging -from typing import Any, Callable, Iterable, TYPE_CHECKING, cast +from typing import Any, TYPE_CHECKING, cast +from collections.abc import Callable +from collections.abc import Iterable from kazoo.handlers.utils import selector_select diff --git a/kazoo/handlers/threading.py b/kazoo/handlers/threading.py index f816652f..bfcf2a28 100644 --- a/kazoo/handlers/threading.py +++ b/kazoo/handlers/threading.py @@ -20,7 +20,9 @@ import threading import time -from typing import Any, Callable, Iterable, TYPE_CHECKING, cast +from typing import Any, TYPE_CHECKING, cast +from collections.abc import Callable +from collections.abc import Iterable from kazoo.handlers import utils from kazoo.handlers.utils import selector_select diff --git a/kazoo/handlers/utils.py b/kazoo/handlers/utils.py index bc420dc0..a4fc0944 100644 --- a/kazoo/handlers/utils.py +++ b/kazoo/handlers/utils.py @@ -10,7 +10,9 @@ import ssl import socket import time -from typing import Any, Callable, Iterable, TypeVar, TYPE_CHECKING +from typing import Any, TypeVar, TYPE_CHECKING +from collections.abc import Callable +from collections.abc import Iterable from typing_extensions import ParamSpec from kazoo.interfaces import IAsyncResult, FdLike diff --git a/kazoo/interfaces.py b/kazoo/interfaces.py index b7b685bb..73daaa25 100644 --- a/kazoo/interfaces.py +++ b/kazoo/interfaces.py @@ -11,14 +11,9 @@ from __future__ import annotations -from typing import ( - Any, - Callable, - Iterable, - Protocol, - Union, - TYPE_CHECKING, -) +from typing import Any, Protocol, Union, TYPE_CHECKING +from collections.abc import Callable +from collections.abc import Iterable if TYPE_CHECKING: from types import TracebackType @@ -34,7 +29,7 @@ class HasFileNo(Protocol): def fileno(self) -> int: ... -FdLike = Union[int, HasFileNo] +FdLike = int | HasFileNo class Socket(HasFileNo, Protocol): @@ -70,7 +65,7 @@ def shutdown(self, flag: int) -> None: ... class Lockable(Protocol): """This is what threading.Lock implements. - In python 3.9+ it's available natively. Though given it has some + In python 3.10+ it's available natively. Though given it has some very odd typing, I wouldn't put money on it. """ diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py index 18df3daa..3ee5969a 100644 --- a/kazoo/protocol/connection.py +++ b/kazoo/protocol/connection.py @@ -3,7 +3,7 @@ from __future__ import annotations from binascii import hexlify -from contextlib import contextmanager +from contextlib import contextmanager, AbstractContextManager import copy import logging import random @@ -11,16 +11,9 @@ import socket import ssl import time -from typing import ( - Callable, - ContextManager, - Iterator, - Literal, - TypeVar, - TYPE_CHECKING, - cast, - overload, -) +from typing import Literal, TypeVar, TYPE_CHECKING, cast, overload +from collections.abc import Callable +from collections.abc import Iterator from typing_extensions import Buffer from kazoo.exceptions import ( @@ -54,11 +47,7 @@ WatchedEvent, EVENT_TYPE_MAP, ) -from kazoo.retry import ( - ForceRetryError, - KazooRetry, - RetryFailedError, -) +from kazoo.retry import ForceRetryError, KazooRetry, RetryFailedError if TYPE_CHECKING: from kazoo.client import KazooClient, WatchFunc @@ -120,7 +109,7 @@ def __init__( self, hosts: list[tuple[str, int]], connection_func: Callable[[tuple[str, int]], Socket], - socket_handling: Callable[[], ContextManager[None]], + socket_handling: Callable[[], AbstractContextManager[None]], ): self.hosts = hosts self.connection = connection_func @@ -224,7 +213,7 @@ def __init__( def _socket_error_handling(self) -> Iterator[None]: try: yield - except (socket.error, select.error) as e: + except OSError as e: err = getattr(e, "strerror", e) raise ConnectionDropped("socket connection error: %s" % (err,)) diff --git a/kazoo/protocol/serialization.py b/kazoo/protocol/serialization.py index 4653c1e5..63b0293e 100644 --- a/kazoo/protocol/serialization.py +++ b/kazoo/protocol/serialization.py @@ -1,16 +1,18 @@ """Zookeeper Serializers, Deserializers, and namedtuple objects -Note: On python3.8, you can't do classvars with NamedTuple. +FIXME Currently we use namedtuple rather than NamedTuple for the various +classes in here, because you can't use a ClassVar in a NamedTuple. This means +the type safety isn't great. -FIXME As soon as we get off python3.8 we should change the namedtuple objects -to NamedTuple, as it should get better typechecking. +This does need refactoring, but not sure how yet. """ from __future__ import annotations import struct from collections import namedtuple -from typing import ClassVar, Sequence, Union, TYPE_CHECKING +from typing import ClassVar, Union, TYPE_CHECKING +from collections.abc import Sequence from kazoo.exceptions import EXCEPTIONS, ZookeeperError from kazoo.protocol.states import ZnodeStat @@ -394,7 +396,7 @@ def serialize(self) -> bytearray: # FIXME Transaction class should move after Create2 Transaction_Types = Union[Create, "Create2", Delete, SetData, CheckVersion] -Transaction_Response = Union[str, bool, ZnodeStat, ZookeeperError, None] +Transaction_Response = str | bool | ZnodeStat | ZookeeperError | None class Transaction(namedtuple("Transaction", "operations")): diff --git a/kazoo/protocol/states.py b/kazoo/protocol/states.py index e2dc03fd..18885129 100644 --- a/kazoo/protocol/states.py +++ b/kazoo/protocol/states.py @@ -3,7 +3,9 @@ from __future__ import annotations from enum import Enum -from typing import Any, Callable, Iterable, NamedTuple +from typing import Any, NamedTuple +from collections.abc import Callable +from collections.abc import Iterable # This is a (str, Enum) for backwards compatibility. diff --git a/kazoo/recipe/cache.py b/kazoo/recipe/cache.py index 48b87680..d123996c 100644 --- a/kazoo/recipe/cache.py +++ b/kazoo/recipe/cache.py @@ -17,17 +17,9 @@ import functools import logging import operator -from typing import ( - Any, - Callable, - Generator, - Protocol, - TypeVar, - Tuple, - TYPE_CHECKING, - Union, - overload, -) +from typing import Any, Protocol, TypeVar, TYPE_CHECKING, Union, overload +from collections.abc import Callable +from collections.abc import Generator from kazoo.exceptions import NoNodeError, KazooException @@ -434,7 +426,7 @@ def _process_result( # FIXME these Tuple-based classes would look a lot better using NamedTuple # though the event_type in TreeEvent needs sorting. -class TreeEvent(Tuple[int, Union["NodeData", None]]): +class TreeEvent(tuple[int, Union["NodeData", None]]): """The immutable event tuple of cache.""" # FIXME These should be an enum. @@ -472,7 +464,7 @@ def make( return cls((event_type, event_data)) -class NodeData(Tuple[str, bytes, ZnodeStat]): +class NodeData(tuple[str, bytes, ZnodeStat]): """The immutable node data tuple of cache.""" #: The absolute path string of current node. diff --git a/kazoo/recipe/counter.py b/kazoo/recipe/counter.py index 77d68cb5..387e2b0e 100644 --- a/kazoo/recipe/counter.py +++ b/kazoo/recipe/counter.py @@ -17,7 +17,7 @@ from kazoo.client import KazooClient -Number = Union[int, float] +Number = int | float class Counter: @@ -117,7 +117,7 @@ def _value(self) -> tuple[Number, int]: # else: # old = val.decode("ascii") # maybe (not sure it does anything for the messy type though) - old: Union[bytes, str, Number] + old: bytes | str | Number old, stat = self.client.get(self.path) if self.support_curator: old = struct.unpack(">i", old)[0] if old != b"" else self.default diff --git a/kazoo/recipe/election.py b/kazoo/recipe/election.py index 4c440003..b3f8f3b1 100644 --- a/kazoo/recipe/election.py +++ b/kazoo/recipe/election.py @@ -7,7 +7,8 @@ from __future__ import annotations -from typing import Callable, TYPE_CHECKING +from typing import TYPE_CHECKING +from collections.abc import Callable from typing_extensions import ParamSpec from kazoo.exceptions import CancelledError diff --git a/kazoo/recipe/lease.py b/kazoo/recipe/lease.py index ace93183..6b1dddd1 100644 --- a/kazoo/recipe/lease.py +++ b/kazoo/recipe/lease.py @@ -11,7 +11,8 @@ import datetime import json import socket -from typing import Callable, TypedDict, TYPE_CHECKING, cast +from typing import TypedDict, TYPE_CHECKING, cast +from collections.abc import Callable from kazoo.exceptions import CancelledError diff --git a/kazoo/recipe/lock.py b/kazoo/recipe/lock.py index 1737802b..c6a8cc44 100644 --- a/kazoo/recipe/lock.py +++ b/kazoo/recipe/lock.py @@ -20,12 +20,9 @@ import re import time import uuid -from typing import ( - Iterable, - Literal, - Pattern, - TYPE_CHECKING, -) +from typing import Literal, TYPE_CHECKING +from re import Pattern +from collections.abc import Iterable from kazoo.exceptions import ( CancelledError, @@ -34,11 +31,7 @@ NoNodeError, ) from kazoo.protocol.states import KazooState, WatchedEvent -from kazoo.retry import ( - ForceRetryError, - KazooRetry, - RetryFailedError, -) +from kazoo.retry import ForceRetryError, KazooRetry, RetryFailedError if TYPE_CHECKING: from types import TracebackType diff --git a/kazoo/recipe/partitioner.py b/kazoo/recipe/partitioner.py index 6e294172..2696cbbc 100644 --- a/kazoo/recipe/partitioner.py +++ b/kazoo/recipe/partitioner.py @@ -25,14 +25,9 @@ import os import socket from enum import Enum -from typing import ( - Callable, - Generic, - Iterator, - Iterable, - TYPE_CHECKING, - TypeVar, -) +from typing import Generic, TYPE_CHECKING, TypeVar +from collections.abc import Callable +from collections.abc import Iterator, Iterable from kazoo.exceptions import KazooException, LockTimeout from kazoo.protocol.states import KazooState @@ -247,8 +242,7 @@ def __init__( def __iter__(self) -> Iterator[PartitionDataT]: """Return the partitions in this partition set""" - for partition in self._partition_set: - yield partition + yield from self._partition_set @property def failed(self) -> bool: diff --git a/kazoo/recipe/party.py b/kazoo/recipe/party.py index a51fc2a8..f58a8a4b 100644 --- a/kazoo/recipe/party.py +++ b/kazoo/recipe/party.py @@ -11,7 +11,8 @@ from __future__ import annotations import uuid -from typing import Iterator, TYPE_CHECKING +from typing import TYPE_CHECKING +from collections.abc import Iterator from kazoo.exceptions import NodeExistsError, NoNodeError diff --git a/kazoo/recipe/watchers.py b/kazoo/recipe/watchers.py index e13b9892..c492486f 100644 --- a/kazoo/recipe/watchers.py +++ b/kazoo/recipe/watchers.py @@ -17,15 +17,8 @@ import logging import time import warnings -from typing import ( - Any, - List, - Callable, - Optional, - Union, - TYPE_CHECKING, - overload, -) +from typing import Any, Optional, Union, TYPE_CHECKING, overload +from collections.abc import Callable from typing_extensions import ParamSpec, deprecated from kazoo.exceptions import ConnectionClosedError, NoNodeError, KazooException @@ -57,13 +50,12 @@ def wrapper(*args: GenericArgs.args, **kwargs: GenericArgs.kwargs) -> None: return wrapper -DataWatchFunc = Union[ - Callable[[Optional[bytes], Optional[ZnodeStat]], Optional[bool]], - Callable[ - [Optional[bytes], Optional[ZnodeStat], Optional[WatchedEvent]], - Optional[bool], - ], -] +DataWatchFunc = ( + Callable[[bytes | None, ZnodeStat | None], bool | None] + | Callable[ + [bytes | None, ZnodeStat | None, WatchedEvent | None], bool | None + ] +) class DataWatch: @@ -119,10 +111,7 @@ def my_func(data, stat, event): @overload def __init__( - self, - client: KazooClient, - path: str, - func: DataWatchFunc | None = None, + self, client: KazooClient, path: str, func: DataWatchFunc | None = None ): ... @overload @@ -294,10 +283,10 @@ def _session_watcher(self, state: KazooState) -> None: self._client.handler.spawn(self._get_data) -ChildrenWatchFunc = Union[ - Callable[[List[str]], Optional[bool]], - Callable[[List[str], Optional[WatchedEvent]], Optional[bool]], -] +ChildrenWatchFunc = ( + Callable[[list[str]], bool | None] + | Callable[[list[str], WatchedEvent | None], bool | None] +) class ChildrenWatch: diff --git a/kazoo/retry.py b/kazoo/retry.py index f5a54428..ec6e5df6 100644 --- a/kazoo/retry.py +++ b/kazoo/retry.py @@ -3,7 +3,8 @@ import logging import random import time -from typing import Any, Callable, TypeVar +from typing import Any, TypeVar +from collections.abc import Callable from kazoo.exceptions import ( ConnectionClosedError, diff --git a/kazoo/testing/harness.py b/kazoo/testing/harness.py index 8e98326d..01ea7842 100644 --- a/kazoo/testing/harness.py +++ b/kazoo/testing/harness.py @@ -8,7 +8,8 @@ import uuid import unittest -from typing import Any, Callable, Literal, cast, TYPE_CHECKING +from typing import Any, Literal, cast, TYPE_CHECKING +from collections.abc import Callable if TYPE_CHECKING: import kazoo.interfaces diff --git a/kazoo/tests/test_connection.py b/kazoo/tests/test_connection.py index 7f9021fc..48e41735 100644 --- a/kazoo/tests/test_connection.py +++ b/kazoo/tests/test_connection.py @@ -10,7 +10,8 @@ import struct import sys -from typing import Any, Iterable, Deque, Tuple, TYPE_CHECKING +from typing import Any, TYPE_CHECKING +from collections.abc import Iterable import pytest from kazoo.exceptions import ConnectionLoss, NotReadOnlyCallError @@ -409,8 +410,8 @@ def log_exception(*args: Any) -> None: assert self._zk_loop_errors[0] == exc_info[1] -class _naughty_deque(Deque[Tuple[Any, Any, int]]): - def append(self, s: Tuple[Any, Any, int]) -> None: +class _naughty_deque(deque[tuple[Any, Any, int]]): + def append(self, s: tuple[Any, Any, int]) -> None: request, async_object, xid = s deque.append(self, (request, async_object, xid + 1)) # +1s diff --git a/kazoo/tests/test_eventlet_handler.py b/kazoo/tests/test_eventlet_handler.py index e410496a..d77440f5 100644 --- a/kazoo/tests/test_eventlet_handler.py +++ b/kazoo/tests/test_eventlet_handler.py @@ -3,7 +3,8 @@ import contextlib import unittest -from typing import Generator, Literal, TYPE_CHECKING +from typing import Literal, TYPE_CHECKING +from collections.abc import Generator import pytest @@ -117,7 +118,7 @@ def test_get_with_no_block(self) -> None: def test_async_exception(self) -> None: def broken() -> None: - raise IOError("Failed") + raise OSError("Failed") with start_stop_one() as handler: r = handler.async_result() @@ -136,7 +137,7 @@ def test_huge_file_descriptor(self) -> None: try: resource.setrlimit(resource.RLIMIT_NOFILE, (4096, 4096)) - except (ValueError, resource.error): + except (OSError, ValueError): self.skipTest("couldn't raise fd limit high enough") fd = 0 socks = [] diff --git a/kazoo/tests/test_gevent_handler.py b/kazoo/tests/test_gevent_handler.py index eda2505e..230e10ee 100644 --- a/kazoo/tests/test_gevent_handler.py +++ b/kazoo/tests/test_gevent_handler.py @@ -3,7 +3,7 @@ import unittest import sys -from typing import Any, Type +from typing import Any import pytest from kazoo.exceptions import NoNodeError @@ -26,10 +26,10 @@ class TestGeventHandler(unittest.TestCase): def _makeOne(self, *args: Any) -> SequentialGeventHandler: return SequentialGeventHandler(*args) - def _getAsync(self) -> Type[AsyncResult[Any]]: + def _getAsync(self) -> type[AsyncResult[Any]]: return AsyncResult - def _getEvent(self) -> Type[Event]: + def _getEvent(self) -> type[Event]: return Event def test_proper_threading(self) -> None: @@ -84,7 +84,7 @@ def setUp(self) -> None: def _makeOne(self, *args: Any) -> SequentialGeventHandler: return SequentialGeventHandler(*args) - def _getEvent(self) -> Type[Event]: + def _getEvent(self) -> type[Event]: return Event def test_start(self) -> None: @@ -142,7 +142,7 @@ def test_huge_file_descriptor(self) -> None: self.skipTest("resource module unavailable on this platform") try: resource.setrlimit(resource.RLIMIT_NOFILE, (4096, 4096)) - except (ValueError, resource.error): + except (OSError, ValueError): self.skipTest("couldn't raise fd limit high enough") fd = 0 socks = [] diff --git a/kazoo/tests/test_lock.py b/kazoo/tests/test_lock.py index d03c2e19..c138ca8b 100644 --- a/kazoo/tests/test_lock.py +++ b/kazoo/tests/test_lock.py @@ -6,7 +6,8 @@ from unittest.mock import MagicMock import uuid -from typing import Any, Callable, Deque, TYPE_CHECKING +from typing import Any, TYPE_CHECKING +from collections.abc import Callable from threading import Thread import pytest @@ -27,7 +28,7 @@ class SleepBarrier: def __init__(self, wait_for: int, sleep_func: Callable[..., None]): self._wait_for = wait_for - self._arrived: Deque[Thread] = collections.deque() + self._arrived: collections.deque[Thread] = collections.deque() self._sleep_func = sleep_func def __enter__(self) -> SleepBarrier: @@ -335,7 +336,7 @@ def test_lock_same_thread_no_block(self) -> None: def test_lock_many_threads_no_block(self) -> None: lock = self.client.Lock(self.lockpath, "one") - attempts: Deque[int] = collections.deque() + attempts: collections.deque[int] = collections.deque() def _acquire() -> None: attempts.append(int(lock.acquire(blocking=False))) @@ -355,8 +356,8 @@ def _acquire() -> None: def test_lock_many_threads(self) -> None: sleep_func = self.client.handler.sleep_func lock = self.client.Lock(self.lockpath, "one") - acquires: Deque[int] = collections.deque() - differences: Deque[int] = collections.deque() + acquires: collections.deque[int] = collections.deque() + differences: collections.deque[int] = collections.deque() barrier = SleepBarrier(self.thread_count, sleep_func) def _acquire() -> None: diff --git a/kazoo/tests/test_retry.py b/kazoo/tests/test_retry.py index 9e67c627..1de852b8 100644 --- a/kazoo/tests/test_retry.py +++ b/kazoo/tests/test_retry.py @@ -28,7 +28,7 @@ def _make_try_func(times: int = 1) -> mock.Mock: returning None. """ callmock = mock.Mock( - side_effect=[kr.ForceRetryError("Failed!")] * times + [None], + side_effect=[kr.ForceRetryError("Failed!")] * times + [None] ) return callmock diff --git a/kazoo/tests/test_sasl.py b/kazoo/tests/test_sasl.py index 549d6cf5..4e2b27b1 100644 --- a/kazoo/tests/test_sasl.py +++ b/kazoo/tests/test_sasl.py @@ -7,10 +7,7 @@ import pytest from kazoo.testing import KazooTestHarness -from kazoo.exceptions import ( - AuthFailedError, - NoAuthError, -) +from kazoo.exceptions import AuthFailedError, NoAuthError class TestLegacySASLDigestAuthentication(KazooTestHarness): diff --git a/kazoo/tests/test_threading_handler.py b/kazoo/tests/test_threading_handler.py index 108be66f..fe4f8acc 100644 --- a/kazoo/tests/test_threading_handler.py +++ b/kazoo/tests/test_threading_handler.py @@ -4,7 +4,7 @@ import threading import unittest -from typing import Any, Type +from typing import Any from unittest.mock import Mock import pytest @@ -17,7 +17,7 @@ class TestThreadingHandler(unittest.TestCase): def _makeOne(self, *args: Any) -> SequentialThreadingHandler: return SequentialThreadingHandler(*args) - def _getAsync(self) -> Type[AsyncResult]: + def _getAsync(self) -> type[AsyncResult]: return AsyncResult def test_proper_threading(self) -> None: @@ -53,7 +53,7 @@ def test_huge_file_descriptor(self) -> None: self.skipTest("resource module unavailable on this platform") try: resource.setrlimit(resource.RLIMIT_NOFILE, (4096, 4096)) - except (ValueError, resource.error): + except (OSError, ValueError): self.skipTest("couldn't raise fd limit high enough") fd = 0 socks = [] diff --git a/kazoo/tests/test_watchers.py b/kazoo/tests/test_watchers.py index 8ce47762..c60379bc 100644 --- a/kazoo/tests/test_watchers.py +++ b/kazoo/tests/test_watchers.py @@ -4,7 +4,7 @@ import threading import uuid -from typing import Any, List, Literal +from typing import Any, Literal import pytest @@ -233,7 +233,7 @@ def changed(children: list[str] | None) -> None: assert children_watch._stopped is True def test_watcher_evaluating_to_false(self) -> None: - class WeirdWatcher(List[Any]): + class WeirdWatcher(list[Any]): def __call__(self, *args: Any) -> None: self.called = True diff --git a/kazoo/tests/util.py b/kazoo/tests/util.py index 56581f1a..5496a1ac 100644 --- a/kazoo/tests/util.py +++ b/kazoo/tests/util.py @@ -17,7 +17,8 @@ import logging import time -from typing import Any, Callable, Type +from typing import Any +from collections.abc import Callable class Handler(logging.Handler): @@ -89,7 +90,7 @@ def __init__( self, timeout: int | None = None, wait: float | None = None, - exception: Type[Exception] = TimeOutWaitingFor, + exception: type[Exception] = TimeOutWaitingFor, getnow: Callable[[], Callable[[], float]] = (lambda: time.monotonic), getsleep: Callable[[], Callable[[float], None]] = (lambda: time.sleep), ): diff --git a/pyproject.toml b/pyproject.toml index 3390b1da..335d84a3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,13 +108,13 @@ exclude = [ ] [tool.ruff.lint] -select = ["E", "F", "W"] +select = ["E", "F", "W", "U"] ignore = [ "E203", # whitespace before ':' (black compatibility) "E721", # do not compare types, use 'isinstance()' "F401", # module imported but unused - "F811", # redefinition of unused name - "F821", # undefined name + "UP031", # using format specifiers + "UP032", # use f-string instead of format ] [tool.ruff.format] From 14bd3cad86cde05883207dafeee70ae045805d79 Mon Sep 17 00:00:00 2001 From: Thomas Tanner Date: Fri, 30 Oct 2026 17:57:54 +0000 Subject: [PATCH 4/4] style: Enable import isorting and checking with -I and -T options in ruff --- kazoo/client.py | 39 +++++++++++---------------- kazoo/handlers/eventlet.py | 9 +++---- kazoo/handlers/gevent.py | 23 +++++++--------- kazoo/handlers/threading.py | 6 ++--- kazoo/handlers/utils.py | 13 ++++----- kazoo/interfaces.py | 9 +++---- kazoo/protocol/connection.py | 21 +++++++-------- kazoo/protocol/serialization.py | 5 ++-- kazoo/protocol/states.py | 3 +-- kazoo/recipe/barrier.py | 4 +-- kazoo/recipe/cache.py | 13 +++++---- kazoo/recipe/counter.py | 2 +- kazoo/recipe/election.py | 3 ++- kazoo/recipe/lease.py | 2 +- kazoo/recipe/lock.py | 5 ++-- kazoo/recipe/partitioner.py | 10 +++---- kazoo/recipe/party.py | 2 +- kazoo/recipe/queue.py | 2 +- kazoo/recipe/watchers.py | 7 ++--- kazoo/retry.py | 2 +- kazoo/security.py | 2 +- kazoo/testing/harness.py | 5 ++-- kazoo/tests/conftest.py | 1 - kazoo/tests/test_cache.py | 11 ++++---- kazoo/tests/test_client.py | 26 ++++++++---------- kazoo/tests/test_connection.py | 24 +++++++---------- kazoo/tests/test_counter.py | 3 +-- kazoo/tests/test_election.py | 6 +++-- kazoo/tests/test_eventlet_handler.py | 6 ++--- kazoo/tests/test_exceptions.py | 3 +-- kazoo/tests/test_gevent_handler.py | 7 ++--- kazoo/tests/test_lease.py | 4 +-- kazoo/tests/test_lock.py | 9 +++---- kazoo/tests/test_partitioner.py | 8 +++--- kazoo/tests/test_queue.py | 5 ++-- kazoo/tests/test_sasl.py | 3 ++- kazoo/tests/test_security.py | 1 - kazoo/tests/test_selectors_select.py | 3 +-- kazoo/tests/test_serialization.py | 4 +-- kazoo/tests/test_threading_handler.py | 1 - kazoo/tests/test_utils.py | 8 +++--- kazoo/tests/test_watchers.py | 4 +-- kazoo/tests/util.py | 4 +-- pyproject.toml | 10 +++++-- 44 files changed, 155 insertions(+), 183 deletions(-) diff --git a/kazoo/client.py b/kazoo/client.py index 169defa4..9647b1e3 100644 --- a/kazoo/client.py +++ b/kazoo/client.py @@ -2,24 +2,16 @@ from __future__ import annotations -from collections import defaultdict, deque -from functools import partial import inspect import logging -from os.path import split import re import warnings -from typing import ( - cast, - overload, - Any, - Literal, - Optional, - TypedDict, - TYPE_CHECKING, -) -from collections.abc import Callable -from collections.abc import Iterable, Sequence +from collections import defaultdict, deque +from collections.abc import Callable, Iterable, Sequence +from functools import partial +from os.path import split +from typing import TYPE_CHECKING, Any, Literal, TypedDict, cast, overload + from typing_extensions import ParamSpec, Unpack, deprecated from kazoo.exceptions import ( @@ -28,8 +20,8 @@ ConnectionClosedError, ConnectionLoss, KazooException, - NoNodeError, NodeExistsError, + NoNodeError, SessionExpiredError, WriterNotClosedException, ) @@ -47,12 +39,12 @@ Create2, Delete, Exists, + GetACL, GetChildren, GetChildren2, - GetACL, - SetACL, GetData, Reconfig, + SetACL, SetData, Sync, Transaction, @@ -64,25 +56,26 @@ KeeperState, WatchedEvent, ) -from kazoo.retry import KazooRetry -from kazoo.security import ACL, OPEN_ACL_UNSAFE # convenience API from kazoo.recipe.barrier import Barrier, DoubleBarrier from kazoo.recipe.counter import Counter from kazoo.recipe.election import Election -from kazoo.recipe.lease import NonBlockingLease, MultiNonBlockingLease -from kazoo.recipe.lock import Lock, ReadLock, WriteLock, Semaphore +from kazoo.recipe.lease import MultiNonBlockingLease, NonBlockingLease +from kazoo.recipe.lock import Lock, ReadLock, Semaphore, WriteLock from kazoo.recipe.partitioner import SetPartitioner from kazoo.recipe.party import Party, ShallowParty -from kazoo.recipe.queue import Queue, LockingQueue +from kazoo.recipe.queue import LockingQueue, Queue from kazoo.recipe.watchers import ChildrenWatch, DataWatch +from kazoo.retry import KazooRetry +from kazoo.security import ACL, OPEN_ACL_UNSAFE if TYPE_CHECKING: from types import TracebackType + + from kazoo.handlers.gevent import SequentialGeventHandler from kazoo.interfaces import Event, IAsyncResult, IHandler from kazoo.protocol.states import ZnodeStat - from kazoo.handlers.gevent import SequentialGeventHandler CLOSED_STATES = ( diff --git a/kazoo/handlers/eventlet.py b/kazoo/handlers/eventlet.py index a52d908d..7c62a3e5 100644 --- a/kazoo/handlers/eventlet.py +++ b/kazoo/handlers/eventlet.py @@ -5,16 +5,15 @@ import atexit import contextlib import logging - -from typing import cast, Any, TYPE_CHECKING from collections.abc import Generator +from typing import TYPE_CHECKING, Any, cast import eventlet +from eventlet import queue as green_queue +from eventlet.green import selectors as green_selectors from eventlet.green import socket as green_socket -from eventlet.green import time as green_time from eventlet.green import threading as green_threading -from eventlet.green import selectors as green_selectors -from eventlet import queue as green_queue +from eventlet.green import time as green_time from kazoo.handlers import utils from kazoo.handlers.utils import selector_select diff --git a/kazoo/handlers/gevent.py b/kazoo/handlers/gevent.py index a998e548..4a2fb9da 100644 --- a/kazoo/handlers/gevent.py +++ b/kazoo/handlers/gevent.py @@ -4,32 +4,29 @@ import atexit import logging - -from typing import Any, TYPE_CHECKING, cast -from collections.abc import Callable -from collections.abc import Iterable - - -from kazoo.handlers.utils import selector_select -from kazoo.handlers import utils +from collections.abc import Callable, Iterable +from typing import TYPE_CHECKING, Any, cast # FIXME This is messy. # We don't want to force the user to install gevent, so we need to handle the # case where it's not available, but there should be a cleaner we of doing this # than by importing all of gevent and ignoring all the import errors. import gevent -from gevent import socket import gevent.event import gevent.queue - -import gevent.thread import gevent.selectors -from gevent.lock import Semaphore, RLock +import gevent.thread +from gevent import socket +from gevent.lock import RLock, Semaphore + +from kazoo.handlers import utils +from kazoo.handlers.utils import selector_select if TYPE_CHECKING: + from gevent import Greenlet + from kazoo.interfaces import FdLike, Lockable, Socket from kazoo.protocol.states import Callback - from gevent import Greenlet _using_libevent = gevent.__version__.startswith("0.") diff --git a/kazoo/handlers/threading.py b/kazoo/handlers/threading.py index bfcf2a28..0a8ea478 100644 --- a/kazoo/handlers/threading.py +++ b/kazoo/handlers/threading.py @@ -19,10 +19,8 @@ import socket import threading import time - -from typing import Any, TYPE_CHECKING, cast -from collections.abc import Callable -from collections.abc import Iterable +from collections.abc import Callable, Iterable +from typing import TYPE_CHECKING, Any, cast from kazoo.handlers import utils from kazoo.handlers.utils import selector_select diff --git a/kazoo/handlers/utils.py b/kazoo/handlers/utils.py index a4fc0944..6f6db7ed 100644 --- a/kazoo/handlers/utils.py +++ b/kazoo/handlers/utils.py @@ -2,23 +2,24 @@ from __future__ import annotations -from collections import defaultdict import errno import functools import select import selectors -import ssl import socket +import ssl import time -from typing import Any, TypeVar, TYPE_CHECKING -from collections.abc import Callable -from collections.abc import Iterable +from collections import defaultdict +from collections.abc import Callable, Iterable +from typing import TYPE_CHECKING, Any, TypeVar + from typing_extensions import ParamSpec -from kazoo.interfaces import IAsyncResult, FdLike +from kazoo.interfaces import FdLike, IAsyncResult if TYPE_CHECKING: from types import ModuleType + from kazoo.interfaces import Socket HAS_FNCTL = True diff --git a/kazoo/interfaces.py b/kazoo/interfaces.py index 73daaa25..e00dd70b 100644 --- a/kazoo/interfaces.py +++ b/kazoo/interfaces.py @@ -10,14 +10,13 @@ from __future__ import annotations - -from typing import Any, Protocol, Union, TYPE_CHECKING -from collections.abc import Callable -from collections.abc import Iterable +from collections.abc import Callable, Iterable +from typing import TYPE_CHECKING, Any, Protocol if TYPE_CHECKING: - from types import TracebackType import queue + from types import TracebackType + from kazoo.protocol.states import Callback # public API diff --git a/kazoo/protocol/connection.py b/kazoo/protocol/connection.py index 3ee5969a..3e6a8ff2 100644 --- a/kazoo/protocol/connection.py +++ b/kazoo/protocol/connection.py @@ -2,31 +2,31 @@ from __future__ import annotations -from binascii import hexlify -from contextlib import contextmanager, AbstractContextManager import copy import logging import random -import select import socket import ssl import time -from typing import Literal, TypeVar, TYPE_CHECKING, cast, overload -from collections.abc import Callable -from collections.abc import Iterator +from binascii import hexlify +from collections.abc import Callable, Iterator +from contextlib import AbstractContextManager, contextmanager +from typing import TYPE_CHECKING, Literal, TypeVar, cast, overload + from typing_extensions import Buffer from kazoo.exceptions import ( + EXCEPTIONS, AuthFailedError, ConnectionDropped, - EXCEPTIONS, - SessionExpiredError, - SessionClosedRequireSaslError, NoNodeError, SASLException, + SessionClosedRequireSaslError, + SessionExpiredError, ) from kazoo.loggingsupport import BLATHER from kazoo.protocol.serialization import ( + SASL, Auth, Close, Connect, @@ -36,16 +36,15 @@ Ping, PingInstance, ReplyHeader, - SASL, Transaction, Watch, int_struct, ) from kazoo.protocol.states import ( + EVENT_TYPE_MAP, Callback, KeeperState, WatchedEvent, - EVENT_TYPE_MAP, ) from kazoo.retry import ForceRetryError, KazooRetry, RetryFailedError diff --git a/kazoo/protocol/serialization.py b/kazoo/protocol/serialization.py index 63b0293e..04a0d57c 100644 --- a/kazoo/protocol/serialization.py +++ b/kazoo/protocol/serialization.py @@ -11,13 +11,12 @@ import struct from collections import namedtuple -from typing import ClassVar, Union, TYPE_CHECKING from collections.abc import Sequence +from typing import TYPE_CHECKING, ClassVar, Union from kazoo.exceptions import EXCEPTIONS, ZookeeperError from kazoo.protocol.states import ZnodeStat -from kazoo.security import ACL -from kazoo.security import Id +from kazoo.security import ACL, Id if TYPE_CHECKING: from kazoo.client import KazooClient, WatchFunc diff --git a/kazoo/protocol/states.py b/kazoo/protocol/states.py index 18885129..0867e685 100644 --- a/kazoo/protocol/states.py +++ b/kazoo/protocol/states.py @@ -2,10 +2,9 @@ from __future__ import annotations +from collections.abc import Callable, Iterable from enum import Enum from typing import Any, NamedTuple -from collections.abc import Callable -from collections.abc import Iterable # This is a (str, Enum) for backwards compatibility. diff --git a/kazoo/recipe/barrier.py b/kazoo/recipe/barrier.py index b05e781a..e8ce62d6 100644 --- a/kazoo/recipe/barrier.py +++ b/kazoo/recipe/barrier.py @@ -10,9 +10,9 @@ import os import socket import uuid -from typing import Literal, TYPE_CHECKING +from typing import TYPE_CHECKING, Literal -from kazoo.exceptions import KazooException, NoNodeError, NodeExistsError +from kazoo.exceptions import KazooException, NodeExistsError, NoNodeError from kazoo.protocol.states import EventType, WatchedEvent if TYPE_CHECKING: diff --git a/kazoo/recipe/cache.py b/kazoo/recipe/cache.py index d123996c..cc567982 100644 --- a/kazoo/recipe/cache.py +++ b/kazoo/recipe/cache.py @@ -17,14 +17,13 @@ import functools import logging import operator -from typing import Any, Protocol, TypeVar, TYPE_CHECKING, Union, overload -from collections.abc import Callable -from collections.abc import Generator +from collections.abc import Callable, Generator +from typing import TYPE_CHECKING, Any, Protocol, TypeVar, Union, overload - -from kazoo.exceptions import NoNodeError, KazooException -from kazoo.protocol.paths import _prefix_root, join as kazoo_join -from kazoo.protocol.states import KazooState, EventType, ZnodeStat +from kazoo.exceptions import KazooException, NoNodeError +from kazoo.protocol.paths import _prefix_root +from kazoo.protocol.paths import join as kazoo_join +from kazoo.protocol.states import EventType, KazooState, ZnodeStat if TYPE_CHECKING: from kazoo.client import KazooClient, WatchFunc diff --git a/kazoo/recipe/counter.py b/kazoo/recipe/counter.py index 387e2b0e..b200ed0c 100644 --- a/kazoo/recipe/counter.py +++ b/kazoo/recipe/counter.py @@ -8,7 +8,7 @@ from __future__ import annotations import struct -from typing import Union, TYPE_CHECKING +from typing import TYPE_CHECKING from kazoo.exceptions import BadVersionError from kazoo.retry import ForceRetryError diff --git a/kazoo/recipe/election.py b/kazoo/recipe/election.py index b3f8f3b1..4acfd9c0 100644 --- a/kazoo/recipe/election.py +++ b/kazoo/recipe/election.py @@ -7,8 +7,9 @@ from __future__ import annotations -from typing import TYPE_CHECKING from collections.abc import Callable +from typing import TYPE_CHECKING + from typing_extensions import ParamSpec from kazoo.exceptions import CancelledError diff --git a/kazoo/recipe/lease.py b/kazoo/recipe/lease.py index 6b1dddd1..f167c6de 100644 --- a/kazoo/recipe/lease.py +++ b/kazoo/recipe/lease.py @@ -11,8 +11,8 @@ import datetime import json import socket -from typing import TypedDict, TYPE_CHECKING, cast from collections.abc import Callable +from typing import TYPE_CHECKING, TypedDict, cast from kazoo.exceptions import CancelledError diff --git a/kazoo/recipe/lock.py b/kazoo/recipe/lock.py index c6a8cc44..b0802de4 100644 --- a/kazoo/recipe/lock.py +++ b/kazoo/recipe/lock.py @@ -20,9 +20,9 @@ import re import time import uuid -from typing import Literal, TYPE_CHECKING -from re import Pattern from collections.abc import Iterable +from re import Pattern +from typing import TYPE_CHECKING, Literal from kazoo.exceptions import ( CancelledError, @@ -35,6 +35,7 @@ if TYPE_CHECKING: from types import TracebackType + from kazoo.client import KazooClient diff --git a/kazoo/recipe/partitioner.py b/kazoo/recipe/partitioner.py index 2696cbbc..42e3f9f0 100644 --- a/kazoo/recipe/partitioner.py +++ b/kazoo/recipe/partitioner.py @@ -20,24 +20,24 @@ from __future__ import annotations -from functools import partial import logging import os import socket +from collections.abc import Callable, Iterable, Iterator from enum import Enum -from typing import Generic, TYPE_CHECKING, TypeVar -from collections.abc import Callable -from collections.abc import Iterator, Iterable +from functools import partial +from typing import TYPE_CHECKING, Generic, TypeVar from kazoo.exceptions import KazooException, LockTimeout from kazoo.protocol.states import KazooState from kazoo.recipe.watchers import PatientChildrenWatch if TYPE_CHECKING: + from _typeshed import SupportsRichComparisonT + from kazoo.client import KazooClient from kazoo.interfaces import Event, IAsyncResult from kazoo.recipe.lock import Lock - from _typeshed import SupportsRichComparisonT log = logging.getLogger(__name__) diff --git a/kazoo/recipe/party.py b/kazoo/recipe/party.py index f58a8a4b..c43aedca 100644 --- a/kazoo/recipe/party.py +++ b/kazoo/recipe/party.py @@ -11,8 +11,8 @@ from __future__ import annotations import uuid -from typing import TYPE_CHECKING from collections.abc import Iterator +from typing import TYPE_CHECKING from kazoo.exceptions import NodeExistsError, NoNodeError diff --git a/kazoo/recipe/queue.py b/kazoo/recipe/queue.py index 8ca31ad3..362956c2 100644 --- a/kazoo/recipe/queue.py +++ b/kazoo/recipe/queue.py @@ -15,7 +15,7 @@ import uuid from typing import TYPE_CHECKING -from kazoo.exceptions import NoNodeError, NodeExistsError +from kazoo.exceptions import NodeExistsError, NoNodeError from kazoo.protocol.states import EventType, WatchedEvent from kazoo.retry import ForceRetryError diff --git a/kazoo/recipe/watchers.py b/kazoo/recipe/watchers.py index c492486f..b0cb229e 100644 --- a/kazoo/recipe/watchers.py +++ b/kazoo/recipe/watchers.py @@ -13,15 +13,16 @@ from __future__ import annotations -from functools import partial, wraps import logging import time import warnings -from typing import Any, Optional, Union, TYPE_CHECKING, overload from collections.abc import Callable +from functools import partial, wraps +from typing import TYPE_CHECKING, Any, overload + from typing_extensions import ParamSpec, deprecated -from kazoo.exceptions import ConnectionClosedError, NoNodeError, KazooException +from kazoo.exceptions import ConnectionClosedError, KazooException, NoNodeError from kazoo.protocol.states import KazooState, WatchedEvent, ZnodeStat from kazoo.retry import KazooRetry diff --git a/kazoo/retry.py b/kazoo/retry.py index ec6e5df6..f2a4fece 100644 --- a/kazoo/retry.py +++ b/kazoo/retry.py @@ -3,8 +3,8 @@ import logging import random import time -from typing import Any, TypeVar from collections.abc import Callable +from typing import Any, TypeVar from kazoo.exceptions import ( ConnectionClosedError, diff --git a/kazoo/security.py b/kazoo/security.py index 8f4ca912..8c01876d 100644 --- a/kazoo/security.py +++ b/kazoo/security.py @@ -2,8 +2,8 @@ from __future__ import annotations -from base64 import b64encode import hashlib +from base64 import b64encode from typing import NamedTuple diff --git a/kazoo/testing/harness.py b/kazoo/testing/harness.py index 01ea7842..db6d1235 100644 --- a/kazoo/testing/harness.py +++ b/kazoo/testing/harness.py @@ -5,11 +5,10 @@ import atexit import logging import os -import uuid import unittest - -from typing import Any, Literal, cast, TYPE_CHECKING +import uuid from collections.abc import Callable +from typing import TYPE_CHECKING, Any, Literal, cast if TYPE_CHECKING: import kazoo.interfaces diff --git a/kazoo/tests/conftest.py b/kazoo/tests/conftest.py index 94da635a..a427f9d8 100644 --- a/kazoo/tests/conftest.py +++ b/kazoo/tests/conftest.py @@ -1,5 +1,4 @@ import logging - from typing import Any log = logging.getLogger(__name__) diff --git a/kazoo/tests/test_cache.py b/kazoo/tests/test_cache.py index 15a67201..36a7441a 100644 --- a/kazoo/tests/test_cache.py +++ b/kazoo/tests/test_cache.py @@ -4,20 +4,21 @@ import importlib import sys import uuid -from typing import Any, TYPE_CHECKING +from typing import TYPE_CHECKING, Any +from unittest.mock import Mock, call, patch -from unittest.mock import patch, call, Mock import pytest from objgraph import count as count_refs_by_type -from kazoo.testing import KazooTestHarness from kazoo.exceptions import KazooException -from kazoo.recipe.cache import TreeCache, TreeNode, TreeEvent +from kazoo.recipe.cache import TreeCache, TreeEvent, TreeNode +from kazoo.testing import KazooTestHarness if TYPE_CHECKING: from queue import Queue - from kazoo.handlers.gevent import SequentialGeventHandler + from kazoo.handlers.eventlet import SequentialEventletHandler + from kazoo.handlers.gevent import SequentialGeventHandler from kazoo.handlers.threading import SequentialThreadingHandler diff --git a/kazoo/tests/test_client.py b/kazoo/tests/test_client.py index c0263c1a..a57cecd1 100644 --- a/kazoo/tests/test_client.py +++ b/kazoo/tests/test_client.py @@ -4,16 +4,13 @@ import socket import tempfile import threading -import time -import uuid import unittest - -from typing import Any, TYPE_CHECKING -from unittest.mock import Mock, MagicMock, patch +import uuid +from typing import TYPE_CHECKING, Any +from unittest.mock import MagicMock, Mock, patch import pytest - from kazoo.client import KazooClient from kazoo.exceptions import ( AuthFailedError, @@ -23,34 +20,33 @@ ConnectionClosedError, ConnectionLoss, InvalidACLError, + KazooException, NoAuthError, NoChildrenForEphemeralsError, - NoNodeError, NodeExistsError, + NoNodeError, RolledBackError, SessionExpiredError, - KazooException, ) -from kazoo.protocol.states import KazooState, KeeperState, WatchedEvent from kazoo.handlers.threading import ( - SequentialThreadingHandler, KazooTimeoutError, + SequentialThreadingHandler, ) from kazoo.protocol.connection import _CONNECTION_DROP +from kazoo.protocol.states import KazooState, KeeperState, WatchedEvent from kazoo.retry import KazooRetry from kazoo.security import ( - make_digest_acl_credential, - CREATOR_ALL_ACL, - make_digest_acl, ACL, + CREATOR_ALL_ACL, OPEN_ACL_UNSAFE, + make_digest_acl, + make_digest_acl_credential, ) - from kazoo.testing import KazooTestCase if TYPE_CHECKING: - from kazoo.testing.common import ManagedZooKeeper from kazoo.interfaces import IAsyncResult + from kazoo.testing.common import ManagedZooKeeper class TestClientTransitions(KazooTestCase): diff --git a/kazoo/tests/test_connection.py b/kazoo/tests/test_connection.py index 48e41735..a612f242 100644 --- a/kazoo/tests/test_connection.py +++ b/kazoo/tests/test_connection.py @@ -1,27 +1,23 @@ from __future__ import annotations -from collections import namedtuple, deque import os +import struct +import sys import threading import time -import uuid import unittest +import uuid +from collections import deque, namedtuple +from collections.abc import Iterable +from typing import TYPE_CHECKING, Any from unittest.mock import Mock, patch -import struct -import sys -from typing import Any, TYPE_CHECKING -from collections.abc import Iterable import pytest from kazoo.exceptions import ConnectionLoss, NotReadOnlyCallError -from kazoo.protocol.serialization import ( - Connect, - int_struct, - write_string, -) -from kazoo.protocol.states import KazooState, KeeperState from kazoo.protocol.connection import _CONNECTION_DROP +from kazoo.protocol.serialization import Connect, int_struct, write_string +from kazoo.protocol.states import KazooState, KeeperState from kazoo.testing import KazooTestCase from kazoo.tests.util import wait @@ -420,8 +416,8 @@ class TestConnectionAuthExceptions(unittest.TestCase): def test_connect_attempt_sasl_exception(self) -> None: from kazoo.exceptions import SASLException from kazoo.protocol.connection import ( - ConnectionHandler, STOP_CONNECTING, + ConnectionHandler, ) from kazoo.retry import KazooRetry @@ -447,8 +443,8 @@ def test_connect_attempt_sasl_exception(self) -> None: def test_connect_attempt_session_closed_require_sasl(self) -> None: from kazoo.exceptions import SessionClosedRequireSaslError from kazoo.protocol.connection import ( - ConnectionHandler, STOP_CONNECTING, + ConnectionHandler, ) from kazoo.retry import KazooRetry diff --git a/kazoo/tests/test_counter.py b/kazoo/tests/test_counter.py index 4085b1ca..ba66db4d 100644 --- a/kazoo/tests/test_counter.py +++ b/kazoo/tests/test_counter.py @@ -1,8 +1,7 @@ from __future__ import annotations import uuid - -from typing import Any, TYPE_CHECKING +from typing import TYPE_CHECKING, Any import pytest diff --git a/kazoo/tests/test_election.py b/kazoo/tests/test_election.py index fda3d297..b762c708 100644 --- a/kazoo/tests/test_election.py +++ b/kazoo/tests/test_election.py @@ -1,8 +1,8 @@ from __future__ import annotations -import uuid import sys import threading +import uuid from typing import TYPE_CHECKING, cast import pytest @@ -11,10 +11,12 @@ from kazoo.tests.util import wait if TYPE_CHECKING: - from kazoo.recipe.election import Election from types import TracebackType + from _typeshed import OptExcInfo + from kazoo.recipe.election import Election + class UniqueError(Exception): """Error raised only by test leader function""" diff --git a/kazoo/tests/test_eventlet_handler.py b/kazoo/tests/test_eventlet_handler.py index d77440f5..0f4d5794 100644 --- a/kazoo/tests/test_eventlet_handler.py +++ b/kazoo/tests/test_eventlet_handler.py @@ -2,14 +2,13 @@ import contextlib import unittest - -from typing import Literal, TYPE_CHECKING from collections.abc import Generator +from typing import TYPE_CHECKING, Literal import pytest -from kazoo.handlers.utils import create_tcp_socket from kazoo.handlers import utils +from kazoo.handlers.utils import create_tcp_socket from kazoo.protocol import states as kazoo_states if TYPE_CHECKING: @@ -17,6 +16,7 @@ try: from eventlet.green import socket + from kazoo.handlers import eventlet as eventlet_handler except ImportError: pytestmark = pytest.mark.skip(reason="eventlet not available") diff --git a/kazoo/tests/test_exceptions.py b/kazoo/tests/test_exceptions.py index 0399ca9c..21d6bf83 100644 --- a/kazoo/tests/test_exceptions.py +++ b/kazoo/tests/test_exceptions.py @@ -1,10 +1,9 @@ from __future__ import annotations +from typing import TYPE_CHECKING from unittest import TestCase - import pytest -from typing import TYPE_CHECKING if TYPE_CHECKING: from types import ModuleType diff --git a/kazoo/tests/test_gevent_handler.py b/kazoo/tests/test_gevent_handler.py index 230e10ee..c1a21fb1 100644 --- a/kazoo/tests/test_gevent_handler.py +++ b/kazoo/tests/test_gevent_handler.py @@ -1,9 +1,9 @@ from __future__ import annotations -import unittest import sys - +import unittest from typing import Any + import pytest from kazoo.exceptions import NoNodeError @@ -13,9 +13,10 @@ try: import gevent # noqa: F401 + from gevent import socket from gevent.event import Event from gevent.queue import Empty - from gevent import socket + from kazoo.handlers.gevent import AsyncResult, SequentialGeventHandler except ImportError: pytestmark = pytest.mark.skip(reason="gevent not available") diff --git a/kazoo/tests/test_lease.py b/kazoo/tests/test_lease.py index cef9d85a..789852ce 100644 --- a/kazoo/tests/test_lease.py +++ b/kazoo/tests/test_lease.py @@ -3,9 +3,7 @@ import datetime import uuid -from kazoo.recipe.lease import NonBlockingLease -from kazoo.recipe.lease import MultiNonBlockingLease - +from kazoo.recipe.lease import MultiNonBlockingLease, NonBlockingLease from kazoo.testing import KazooTestCase diff --git a/kazoo/tests/test_lock.py b/kazoo/tests/test_lock.py index c138ca8b..d4e50dde 100644 --- a/kazoo/tests/test_lock.py +++ b/kazoo/tests/test_lock.py @@ -3,18 +3,15 @@ import collections import threading import unittest -from unittest.mock import MagicMock import uuid - -from typing import Any, TYPE_CHECKING from collections.abc import Callable from threading import Thread +from typing import TYPE_CHECKING, Any +from unittest.mock import MagicMock import pytest -from kazoo.exceptions import CancelledError -from kazoo.exceptions import LockTimeout -from kazoo.exceptions import NoNodeError +from kazoo.exceptions import CancelledError, LockTimeout, NoNodeError from kazoo.recipe.lock import Lock, Semaphore from kazoo.testing import KazooTestCase from kazoo.tests import util as test_util diff --git a/kazoo/tests/test_partitioner.py b/kazoo/tests/test_partitioner.py index 35f7f484..5d70d273 100644 --- a/kazoo/tests/test_partitioner.py +++ b/kazoo/tests/test_partitioner.py @@ -1,18 +1,18 @@ from __future__ import annotations -import uuid import threading import time +import uuid +from typing import TYPE_CHECKING from unittest.mock import patch from kazoo.exceptions import LockTimeout -from kazoo.testing import KazooTestCase from kazoo.recipe.partitioner import PartitionState, SetPartitioner -from typing import TYPE_CHECKING +from kazoo.testing import KazooTestCase if TYPE_CHECKING: - from kazoo.interfaces import Lockable from kazoo.client import KazooClient + from kazoo.interfaces import Lockable class SlowLockMock: diff --git a/kazoo/tests/test_queue.py b/kazoo/tests/test_queue.py index d88b452d..3796ec22 100644 --- a/kazoo/tests/test_queue.py +++ b/kazoo/tests/test_queue.py @@ -1,16 +1,15 @@ from __future__ import annotations import uuid - -from typing import Any, TYPE_CHECKING +from typing import TYPE_CHECKING, Any import pytest from kazoo.testing import KazooTestCase if TYPE_CHECKING: - from kazoo.recipe.queue import LockingQueue, Queue from kazoo.interfaces import Event + from kazoo.recipe.queue import LockingQueue, Queue class KazooQueueTests(KazooTestCase): diff --git a/kazoo/tests/test_sasl.py b/kazoo/tests/test_sasl.py index 4e2b27b1..5a07d18d 100644 --- a/kazoo/tests/test_sasl.py +++ b/kazoo/tests/test_sasl.py @@ -6,8 +6,8 @@ import pytest -from kazoo.testing import KazooTestHarness from kazoo.exceptions import AuthFailedError, NoAuthError +from kazoo.testing import KazooTestHarness class TestLegacySASLDigestAuthentication(KazooTestHarness): @@ -109,6 +109,7 @@ def test_invalid_sasl_auth(self) -> None: class TestSASLGSSAPIAuthentication(KazooTestHarness): def setUp(self) -> None: # puresasl isn't available under windows, so we can't do this test. + # ruff: noqa: F401 try: import puresasl except ImportError: diff --git a/kazoo/tests/test_security.py b/kazoo/tests/test_security.py index ba21862b..8cd38714 100644 --- a/kazoo/tests/test_security.py +++ b/kazoo/tests/test_security.py @@ -1,7 +1,6 @@ from __future__ import annotations import unittest - from typing import Any from kazoo.security import ACL, Permissions diff --git a/kazoo/tests/test_selectors_select.py b/kazoo/tests/test_selectors_select.py index 0d9e77da..48464ce1 100644 --- a/kazoo/tests/test_selectors_select.py +++ b/kazoo/tests/test_selectors_select.py @@ -9,8 +9,7 @@ import subprocess import sys import unittest - -from typing import cast, TYPE_CHECKING +from typing import TYPE_CHECKING, cast from kazoo.handlers.utils import selector_select diff --git a/kazoo/tests/test_serialization.py b/kazoo/tests/test_serialization.py index ff339c09..a0f0d9a9 100644 --- a/kazoo/tests/test_serialization.py +++ b/kazoo/tests/test_serialization.py @@ -3,13 +3,13 @@ import struct import unittest +from unittest_parametrize import ParametrizedTestCase, param, parametrize + from kazoo.exceptions import ZookeeperError from kazoo.protocol import serialization from kazoo.protocol.states import ZnodeStat from kazoo.security import ACL, Id -from unittest_parametrize import ParametrizedTestCase, parametrize, param - _int_struct = struct.Struct("!i") _int_int_struct = struct.Struct("!ii") _int_int_long_struct = struct.Struct("!iiq") diff --git a/kazoo/tests/test_threading_handler.py b/kazoo/tests/test_threading_handler.py index fe4f8acc..f88a790b 100644 --- a/kazoo/tests/test_threading_handler.py +++ b/kazoo/tests/test_threading_handler.py @@ -3,7 +3,6 @@ import socket import threading import unittest - from typing import Any from unittest.mock import Mock diff --git a/kazoo/tests/test_utils.py b/kazoo/tests/test_utils.py index 50c7cbbf..532b7b10 100644 --- a/kazoo/tests/test_utils.py +++ b/kazoo/tests/test_utils.py @@ -1,17 +1,17 @@ from __future__ import annotations import errno -import ssl import socket +import ssl import time -from kazoo.handlers import utils -from kazoo.handlers.utils import create_tcp_connection - import unittest from unittest.mock import patch import pytest +from kazoo.handlers import utils +from kazoo.handlers.utils import create_tcp_connection + try: from eventlet.green import socket as green_socket diff --git a/kazoo/tests/test_watchers.py b/kazoo/tests/test_watchers.py index c60379bc..f66bb18d 100644 --- a/kazoo/tests/test_watchers.py +++ b/kazoo/tests/test_watchers.py @@ -1,9 +1,8 @@ from __future__ import annotations -import time import threading +import time import uuid - from typing import Any, Literal import pytest @@ -11,7 +10,6 @@ from kazoo.exceptions import KazooException from kazoo.protocol.states import EventType, WatchedEvent, ZnodeStat from kazoo.recipe.watchers import PatientChildrenWatch - from kazoo.testing import KazooTestCase diff --git a/kazoo/tests/util.py b/kazoo/tests/util.py index 5496a1ac..9fa4369f 100644 --- a/kazoo/tests/util.py +++ b/kazoo/tests/util.py @@ -13,12 +13,10 @@ # FOR A PARTICULAR PURPOSE. # ############################################################################## - import logging import time - -from typing import Any from collections.abc import Callable +from typing import Any class Handler(logging.Handler): diff --git a/pyproject.toml b/pyproject.toml index 335d84a3..6cbcddc8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,11 +108,17 @@ exclude = [ ] [tool.ruff.lint] -select = ["E", "F", "W", "U"] +select = [ + "E", # Python codestyle errors + "F", # pyflake errors + "I", # import-related errors + "T", # flake8-tidy-imports errors + "W", # Python codestyle warnings + "U" # upgrade errors +] ignore = [ "E203", # whitespace before ':' (black compatibility) "E721", # do not compare types, use 'isinstance()' - "F401", # module imported but unused "UP031", # using format specifiers "UP032", # use f-string instead of format ]