Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions kazoo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class KazooRetryParams(TypedDict, total=False):
interrupt: Callable[[], bool]


class KazooClient(object):
class KazooClient:
"""An Apache Zookeeper Python client supporting alternate callback
handlers and high-level functionality.

Expand Down Expand Up @@ -989,7 +989,7 @@ def _try_fetch() -> tuple[int, ...] | None:
1
)
try:
return tuple([int(d) for d in version_digits.split(".")])
return tuple(int(d) for d in version_digits.split("."))
except ValueError:
return None

Expand Down Expand Up @@ -1966,7 +1966,7 @@ def reconfig_async(
return async_result


class TransactionRequest(object):
class TransactionRequest:
"""A Zookeeper Transaction Request

A Transaction provides a builder object that can be used to
Expand Down
5 changes: 2 additions & 3 deletions kazoo/handlers/eventlet.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""A eventlet based handler."""

from __future__ import annotations
from __future__ import absolute_import

import atexit
import contextlib
Expand Down Expand Up @@ -59,15 +58,15 @@ class AsyncResult(utils.AsyncResult):
"""A one-time event that stores a value or an exception"""

def __init__(self, handler: IHandler):
super(AsyncResult, self).__init__(
super().__init__(
handler,
green_threading.Condition, # type: ignore[attr-defined]
TimeoutError,
)


# FIXME This should inherit from IHandler
class SequentialEventletHandler(object):
class SequentialEventletHandler:
"""Eventlet handler for sequentially executing callbacks.

This handler executes callbacks in a sequential manner. A queue is
Expand Down
3 changes: 1 addition & 2 deletions kazoo/handlers/gevent.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""A gevent based handler."""

from __future__ import annotations
from __future__ import absolute_import

import atexit
import logging
Expand Down Expand Up @@ -47,7 +46,7 @@
# CallbackQueue = gevent.queue.Queue[Callable[..., None]]


class SequentialGeventHandler(object):
class SequentialGeventHandler:
"""Gevent handler for sequentially executing callbacks.
This handler executes callbacks in a sequential manner. A queue is
Expand Down
5 changes: 1 addition & 4 deletions kazoo/handlers/threading.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"""

from __future__ import annotations
from __future__ import absolute_import

import atexit
import logging
Expand Down Expand Up @@ -71,9 +70,7 @@ class AsyncResult(utils.AsyncResult):
"""A one-time event that stores a value or an exception"""

def __init__(self, handler: Any) -> None:
super(AsyncResult, self).__init__(
handler, threading.Condition, KazooTimeoutError
)
super().__init__(handler, threading.Condition, KazooTimeoutError)


class SequentialThreadingHandler(IHandler):
Expand Down
20 changes: 5 additions & 15 deletions kazoo/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,21 +305,11 @@ def create_tcp_connection(
# otherwise there is no timeout set and we'll call it as such
sock = module.create_connection(address, timeout_at)
break
except Exception as ex:
# FIXME The check for ex[0] is for compatibility with python 2
# and should be removed. Instead we should just catch
# InterruptedError and continue. Even this is unnecessary, at
# least for 'socket', since PEP475 was adopted in python 3.5
# but I'm not entirely sure about the gevent and eventlet
# libraries.
errnum = (
ex.errno
if isinstance(ex, OSError)
else ex[0] # type: ignore
)
if errnum == errno.EINTR:
continue
raise
except InterruptedError:
# Retry on an interrupted connect attempt. This is a
# standard Python 3 socket behavior and is enough for the
# supported Python versions in this project.
continue

if sock is None:
raise module.error
Expand Down
4 changes: 2 additions & 2 deletions kazoo/protocol/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def buffer(obj: Buffer, offset: int = 0) -> memoryview:
return memoryview(obj)[offset:]


class RWPinger(object):
class RWPinger:
"""A Read/Write Server Pinger Iterable

This object is initialized with the hosts iterator object and the
Expand Down Expand Up @@ -180,7 +180,7 @@ class RWServerAvailable(Exception):
ReturnValue = TypeVar("ReturnValue")


class ConnectionHandler(object):
class ConnectionHandler:
"""Zookeeper connection handler"""

def __init__(
Expand Down
4 changes: 2 additions & 2 deletions kazoo/recipe/barrier.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from kazoo.client import KazooClient


class Barrier(object):
class Barrier:
"""Kazoo Barrier

Implements a barrier to block processing of a set of nodes until
Expand Down Expand Up @@ -83,7 +83,7 @@ def wait_for_clear(event: WatchedEvent) -> None:
return cleared.is_set()


class DoubleBarrier(object):
class DoubleBarrier:
"""Kazoo Double Barrier

Double barriers are used to synchronize the beginning and end of
Expand Down
5 changes: 2 additions & 3 deletions kazoo/recipe/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"""

from __future__ import annotations
from __future__ import absolute_import

import contextlib
import functools
Expand Down Expand Up @@ -46,7 +45,7 @@
ReturnValue = TypeVar("ReturnValue")


class TreeCache(object):
class TreeCache:
"""The cache of a ZooKeeper subtree.

:param client: A :class:`~kazoo.client.KazooClient` instance.
Expand Down Expand Up @@ -274,7 +273,7 @@ def __call__(self, path: str, watch: WatchFunc | None) -> IAsyncResult:
...


class TreeNode(object):
class TreeNode:
"""The tree node record.

:param tree: A :class:`~kazoo.recipe.cache.TreeCache` instance.
Expand Down
2 changes: 1 addition & 1 deletion kazoo/recipe/counter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
Number = Union[int, float]


class Counter(object):
class Counter:
"""Kazoo Counter
A shared counter of either int or float values. Changes to the
Expand Down
2 changes: 1 addition & 1 deletion kazoo/recipe/election.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
GenericArgs = ParamSpec("GenericArgs")


class Election(object):
class Election:
"""Kazoo Basic Leader Election
Example usage with a :class:`~kazoo.client.KazooClient` instance::
Expand Down
4 changes: 2 additions & 2 deletions kazoo/recipe/lease.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Lease(TypedDict):
end: str


class NonBlockingLease(object):
class NonBlockingLease:
"""Exclusive lease that does not block.
An exclusive lease ensures that only one client at a time owns the lease.
Expand Down Expand Up @@ -133,7 +133,7 @@ def __bool__(self) -> bool:
return self.obtained


class MultiNonBlockingLease(object):
class MultiNonBlockingLease:
"""Exclusive lease for multiple clients.
This type of lease is useful when a limited set of hosts should run a
Expand Down
6 changes: 3 additions & 3 deletions kazoo/recipe/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
from kazoo.client import KazooClient


class _Watch(object):
class _Watch:
def __init__(self, duration: float | None = None):
self.duration = duration
self.started_at: float | None = None
Expand All @@ -70,7 +70,7 @@ def leftover(self) -> float | None:
return max(0, self.duration - elapsed)


class Lock(object):
class Lock:
"""Kazoo Lock

Example usage with a :class:`~kazoo.client.KazooClient` instance:
Expand Down Expand Up @@ -503,7 +503,7 @@ class ReadLock(Lock):
_EXCLUDE_NAMES = ["__lock__"]


class Semaphore(object):
class Semaphore:
"""A Zookeeper-based Semaphore

This synchronization primitive operates in the same manner as the
Expand Down
2 changes: 1 addition & 1 deletion kazoo/recipe/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from kazoo.client import KazooClient


class BaseParty(object):
class BaseParty:
"""Base implementation of a party."""

def __init__(
Expand Down
10 changes: 5 additions & 5 deletions kazoo/recipe/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from kazoo.client import KazooClient


class BaseQueue(object):
class BaseQueue:
"""A common base class for queue implementations."""

def __init__(self, client: KazooClient, path: str):
Expand Down Expand Up @@ -74,12 +74,12 @@ def __init__(self, client: KazooClient, path: str):
:param client: A :class:`~kazoo.client.KazooClient` instance.
:param path: The queue path to use in ZooKeeper.
"""
super(Queue, self).__init__(client, path)
super().__init__(client, path)
self._children: list[str] = []

def __len__(self) -> int:
"""Return queue size."""
return super(Queue, self).__len__()
return super().__len__()

def get(self) -> bytes | None:
"""
Expand Down Expand Up @@ -162,7 +162,7 @@ def __init__(self, client: KazooClient, path: str):
:param client: A :class:`~kazoo.client.KazooClient` instance.
:param path: The queue path to use in ZooKeeper.
"""
super(LockingQueue, self).__init__(client, path)
super().__init__(client, path)
self.id = uuid.uuid4().hex.encode()
self.processing_element: tuple[str, bytes] | None = None
self._lock_path = self.path + self.lock
Expand All @@ -174,7 +174,7 @@ def __len__(self) -> int:

:returns: queue size (includes locked entries count).
"""
return super(LockingQueue, self).__len__()
return super().__len__()

def put(self, value: bytes, priority: int = 100) -> None:
"""Put an entry into the queue.
Expand Down
6 changes: 3 additions & 3 deletions kazoo/recipe/watchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def wrapper(*args: GenericArgs.args, **kwargs: GenericArgs.kwargs) -> None:
]


class DataWatch(object):
class DataWatch:
"""Watches a node for data updates and calls the specified
function each time it changes

Expand Down Expand Up @@ -302,7 +302,7 @@ def _session_watcher(self, state: KazooState) -> None:
]


class ChildrenWatch(object):
class ChildrenWatch:
"""Watches a node for children updates and calls the specified
function each time it changes

Expand Down Expand Up @@ -465,7 +465,7 @@ def _session_watcher(self, state: KazooState) -> None:
self._client.handler.spawn(self._get_children)


class PatientChildrenWatch(object):
class PatientChildrenWatch:
"""Patient Children Watch that returns values after the children
of a node don't change for a period of time

Expand Down
2 changes: 1 addition & 1 deletion kazoo/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class InterruptedError(RetryFailedError):
function"""


class KazooRetry(object):
class KazooRetry:
"""Helper for retrying a method in the face of retry-able
exceptions"""

Expand Down
2 changes: 1 addition & 1 deletion kazoo/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __repr__(self) -> str:
)


class Permissions(object):
class Permissions:
READ = 1
WRITE = 2
CREATE = 4
Expand Down
8 changes: 4 additions & 4 deletions kazoo/testing/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def to_java_compatible_path(path: str) -> str:
)


class ManagedZooKeeper(object):
class ManagedZooKeeper:
"""Class to manage the running of a ZooKeeper instance for testing.

Note: no attempt is made to probe the ZooKeeper instance is
Expand Down Expand Up @@ -350,13 +350,13 @@ def destroy(self) -> None:
def get_logs(self, num_lines: int = 100) -> list[str]:
log_path = pathlib.Path(self.working_path, "zookeeper.log")
if log_path.exists():
log_file = log_path.open("r")
lines = log_file.readlines()
with log_path.open("r") as log_file:
lines = log_file.readlines()
return lines[-num_lines:]
return []


class ZookeeperCluster(object):
class ZookeeperCluster:
def __init__(
self,
install_path: str,
Expand Down
4 changes: 2 additions & 2 deletions kazoo/testing/harness.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def get_global_cluster() -> ZookeeperCluster:
if "-" in ZK_VERSION_STR:
# Ignore pre-release markers like -alpha
ZK_VERSION_STR = ZK_VERSION_STR.split("-")[0]
ZK_VERSION = tuple([int(n) for n in ZK_VERSION_STR.split(".")])
ZK_VERSION = tuple(int(n) for n in ZK_VERSION_STR.split("."))
ZK_OBSERVER_START_ID = int( # type: ignore[call-overload]
cluster_conf.get("ZOOKEEPER_OBSERVER_START_ID")
)
Expand Down Expand Up @@ -173,7 +173,7 @@ def test_something_else(self) -> None:
DEFAULT_CLIENT_TIMEOUT = 15

def __init__(self, *args: Any, **kw: Any):
super(KazooTestHarness, self).__init__(*args, **kw)
super().__init__(*args, **kw)
self._client: KazooClient | None = None
self._clients: list[KazooClient] = []

Expand Down
4 changes: 2 additions & 2 deletions kazoo/tests/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def choose_an_installed_handler(

class KazooTreeCacheTests(KazooAdaptiveHandlerTestCase):
def setUp(self) -> None:
super(KazooTreeCacheTests, self).setUp()
super().setUp()
self._event_queue: Queue[TreeEvent] = self.client.handler.queue_impl()
self._error_queue = self.client.handler.queue_impl()
self._path: str | None = None
Expand All @@ -78,7 +78,7 @@ def tearDown(self) -> None:
if self._cache is not None:
self._cache.close()
self._cache = None
super(KazooTreeCacheTests, self).tearDown()
super().tearDown()

def make_cache(self) -> TreeCache:
if self._cache is None:
Expand Down
Loading
Loading