Skip to content

Commit

Permalink
lint / format
Browse files Browse the repository at this point in the history
  • Loading branch information
PythonFZ committed Feb 6, 2025
1 parent 3fccf0f commit 5289e32
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ znsocket = "znsocket.cli:app"
repository = "https://github.com/zincware/ZnSocket"

[tool.ruff.lint]
select = ["I"]
select = ["I", "F", "W", "C"]

[tool.coverage.run]
# omit the tests themselves
Expand Down
2 changes: 0 additions & 2 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
import redis.exceptions

import znsocket.exceptions


@pytest.mark.parametrize("client", ["znsclient", "znsclient_w_redis", "redisclient"])
def test_set(client, request):
Expand Down
2 changes: 1 addition & 1 deletion znsocket/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from znsocket.objects import Dict, List
from znsocket.server import Server, attach_events

__all__ = ["Client", "Server", "List", "Dict"]
__all__ = ["Client", "Server", "List", "Dict", "attach_events"]
2 changes: 0 additions & 2 deletions znsocket/client.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import dataclasses
import datetime
import functools
import json
import logging
import typing as t
import warnings

import socketio.exceptions
import typing_extensions as tyex
Expand Down
22 changes: 11 additions & 11 deletions znsocket/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def __getitem__(self, index: int | list | slice) -> t.Any | list[t.Any]:
items.append(item)
return items[0] if single_item else items

def __setitem__(self, index: int | list | slice, value: t.Any) -> None:
def __setitem__(self, index: int | list | slice, value: t.Any) -> None: # noqa C901
single_item = isinstance(index, int)
if single_item:
index = [index]
Expand Down Expand Up @@ -197,7 +197,7 @@ def __setitem__(self, index: int | list | slice, value: t.Any) -> None:
if self.socket is not None:
refresh: RefreshTypeDict = {"indices": index}
refresh_data: RefreshDataTypeDict = {"target": self.key, "data": refresh}
self.socket.sio.emit(f"refresh", refresh_data, namespace="/znsocket")
self.socket.sio.emit("refresh", refresh_data, namespace="/znsocket")

def __delitem__(self, index: int | list | slice) -> None:
single_item = isinstance(index, int)
Expand All @@ -224,7 +224,7 @@ def __delitem__(self, index: int | list | slice) -> None:
if self.socket is not None:
refresh: RefreshTypeDict = {"start": min(index), "stop": None}
refresh_data: RefreshDataTypeDict = {"target": self.key, "data": refresh}
self.socket.sio.emit(f"refresh", refresh_data, namespace="/znsocket")
self.socket.sio.emit("refresh", refresh_data, namespace="/znsocket")

def insert(self, index: int, value: t.Any) -> None:
if isinstance(value, Dict):
Expand All @@ -248,7 +248,7 @@ def insert(self, index: int, value: t.Any) -> None:
if self.socket is not None:
refresh: RefreshTypeDict = {"start": index, "stop": None}
refresh_data: RefreshDataTypeDict = {"target": self.key, "data": refresh}
self.socket.sio.emit(f"refresh", refresh_data, namespace="/znsocket")
self.socket.sio.emit("refresh", refresh_data, namespace="/znsocket")

def __eq__(self, value: object) -> bool:
if isinstance(value, List):
Expand Down Expand Up @@ -287,7 +287,7 @@ def append(self, value: t.Any) -> None:
if self.socket is not None:
refresh: RefreshTypeDict = {"indices": [len(self) - 1]}
refresh_data: RefreshDataTypeDict = {"target": self.key, "data": refresh}
self.socket.sio.emit(f"refresh", refresh_data, namespace="/znsocket")
self.socket.sio.emit("refresh", refresh_data, namespace="/znsocket")

def extend(self, values: t.Iterable) -> None:
"""Extend the list with an iterable using redis pipelines."""
Expand All @@ -306,7 +306,7 @@ def extend(self, values: t.Iterable) -> None:

if self.socket is not None:
refresh_data: RefreshDataTypeDict = {"target": self.key, "data": refresh}
self.socket.sio.emit(f"refresh", refresh_data, namespace="/znsocket")
self.socket.sio.emit("refresh", refresh_data, namespace="/znsocket")

def pop(self, index: int = -1) -> t.Any:
"""Pop an item from the list."""
Expand All @@ -327,7 +327,7 @@ def pop(self, index: int = -1) -> t.Any:
if self.socket is not None:
refresh: RefreshTypeDict = {"start": index, "stop": None}
refresh_data: RefreshDataTypeDict = {"target": self.key, "data": refresh}
self.socket.sio.emit(f"refresh", refresh_data, namespace="/znsocket")
self.socket.sio.emit("refresh", refresh_data, namespace="/znsocket")
return _decode(self, value)

def copy(self, key: str) -> "List":
Expand Down Expand Up @@ -426,7 +426,7 @@ def __setitem__(self, key: str, value: t.Any) -> None:
if self.socket is not None:
refresh: RefreshTypeDict = {"keys": [key]}
refresh_data: RefreshDataTypeDict = {"target": self.key, "data": refresh}
self.socket.sio.emit(f"refresh", refresh_data, namespace="/znsocket")
self.socket.sio.emit("refresh", refresh_data, namespace="/znsocket")

def __delitem__(self, key: str) -> None:
if not self.redis.hexists(self.key, key):
Expand All @@ -437,7 +437,7 @@ def __delitem__(self, key: str) -> None:
if self.socket is not None:
refresh: RefreshTypeDict = {"keys": [key]}
refresh_data: RefreshDataTypeDict = {"target": self.key, "data": refresh}
self.socket.sio.emit(f"refresh", refresh_data, namespace="/znsocket")
self.socket.sio.emit("refresh", refresh_data, namespace="/znsocket")

def __iter__(self):
return iter(self.keys())
Expand Down Expand Up @@ -486,7 +486,7 @@ def __repr__(self) -> str:
elif self.repr_type == "minimal":
return "Dict(<unknown>)"
elif self.repr_type == "full":
data = {a: b for a, b in self.items()}
data = dict(self.items())
return f"Dict({data})"
else:
raise ValueError(f"Invalid repr_type: {self.repr_type}")
Expand Down Expand Up @@ -546,7 +546,7 @@ def update(self, *args, **kwargs):
if self.socket is not None:
refresh: RefreshTypeDict = {"keys": list(other.keys())}
refresh_data: RefreshDataTypeDict = {"target": self.key, "data": refresh}
self.socket.sio.emit(f"refresh", refresh_data, namespace="/znsocket")
self.socket.sio.emit("refresh", refresh_data, namespace="/znsocket")

def __or__(self, value: "dict|Dict") -> dict:
if isinstance(value, Dict):
Expand Down
2 changes: 1 addition & 1 deletion znsocket/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def get_sio(
return sio


def attach_events(
def attach_events( # noqa: C901
sio: socketio.Server, namespace: str = "/znsocket", storage=None
) -> None:
if storage is None:
Expand Down

0 comments on commit 5289e32

Please sign in to comment.