implement ruff recommendations

This commit is contained in:
Mose Müller 2023-11-28 15:11:46 +01:00
parent 4802f19720
commit 598449e893
8 changed files with 20 additions and 22 deletions

View File

@ -28,7 +28,7 @@ class Image(DataService):
return self._value
@property
def format(self) -> str:
def format(self) -> str: # noqa: A003
return self._format
def load_from_path(self, path: Path | str) -> None:

View File

@ -309,8 +309,8 @@ class CallbackManager:
):
def list_or_data_service_callback(
name: Any, # noqa: ARG001
value: Any, # noqa: ARG001
name: Any,
value: Any,
dependent_attr: str = attr_name,
) -> None:
"""Emits a notification through the service's callback
@ -331,7 +331,7 @@ class CallbackManager:
def callback(
name: str,
value: Any, # noqa: ARG001
value: Any,
dependent_attr: str = attr_name,
dep: str = dependency,
) -> None:

View File

@ -23,7 +23,7 @@ from pydase.utils.serializer import (
get_nested_dict_by_path,
)
from pydase.utils.warnings import (
warn_if_instance_class_does_not_inherit_from_DataService,
warn_if_instance_class_does_not_inherit_from_data_service,
)
if TYPE_CHECKING:
@ -98,7 +98,7 @@ class DataService(rpyc.Service, AbstractDataService):
# every class defined by the user should inherit from DataService if it is
# assigned to a public attribute
if not attr_name.startswith("_"):
warn_if_instance_class_does_not_inherit_from_DataService(attr_value)
warn_if_instance_class_does_not_inherit_from_data_service(attr_value)
def __set_attribute_based_on_type( # noqa: PLR0913
self,

View File

@ -3,7 +3,7 @@ from typing import Any
import pydase.units as u
from pydase.utils.warnings import (
warn_if_instance_class_does_not_inherit_from_DataService,
warn_if_instance_class_does_not_inherit_from_data_service,
)
@ -36,7 +36,7 @@ class DataServiceList(list):
self._callbacks = callback_list
for item in args[0]:
warn_if_instance_class_does_not_inherit_from_DataService(item)
warn_if_instance_class_does_not_inherit_from_data_service(item)
# prevent gc to delete the passed list by keeping a reference
self._original_list = args[0]

View File

@ -164,16 +164,18 @@ class Server:
def __init__( # noqa: PLR0913
self,
service: DataService,
host: str = "0.0.0.0",
host: str = "127.0.0.1",
rpc_port: int = 18871,
web_port: int = 8001,
enable_rpc: bool = True,
enable_web: bool = True,
filename: Optional[str | Path] = None,
use_forking_server: bool = False,
additional_servers: list[AdditionalServer] = [],
additional_servers: list[AdditionalServer] | None = None,
**kwargs: Any,
) -> None:
if additional_servers is None:
additional_servers = []
self._service = service
self._host = host
self._rpc_port = rpc_port
@ -276,10 +278,6 @@ class Server:
)
def sio_callback(parent_path: str, name: str, value: Any) -> None:
# TODO: an error happens when an attribute is set to a list
# > File "/usr/lib64/python3.11/json/encoder.py", line 180, in default
# > raise TypeError(f'Object of type {o.__class__.__name__} '
# > TypeError: Object of type list is not JSON serializable
full_access_path = ".".join([*parent_path.split(".")[1:], name])
cached_value_dict = deepcopy(
get_nested_dict_by_path(self._state_manager.cache, full_access_path)

View File

@ -70,13 +70,13 @@ class WebAPI:
__sio_app: socketio.ASGIApp
__fastapi_app: FastAPI
def __init__(
def __init__( # noqa: PLR0913
self,
service: DataService,
state_manager: StateManager,
frontend: str | Path | None = None,
css: str | Path | None = None,
enable_CORS: bool = True,
enable_cors: bool = True,
*args: Any,
**kwargs: Any,
) -> None:
@ -84,7 +84,7 @@ class WebAPI:
self.state_manager = state_manager
self.frontend = frontend
self.css = css
self.enable_CORS = enable_CORS
self.enable_cors = enable_cors
self.args = args
self.kwargs = kwargs
@ -98,7 +98,7 @@ class WebAPI:
def setup_socketio(self) -> None:
# the socketio ASGI app, to notify clients when params update
if self.enable_CORS:
if self.enable_cors:
sio = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*")
else:
sio = socketio.AsyncServer(async_mode="asgi")
@ -127,7 +127,7 @@ class WebAPI:
def setup_fastapi_app(self) -> None:
app = FastAPI()
if self.enable_CORS:
if self.enable_cors:
app.add_middleware(
CORSMiddleware,
allow_credentials=True,

View File

@ -54,7 +54,7 @@ def get_object_attr_from_path_list(target_obj: Any, path: list[str]) -> Any:
index_str = index_str.replace("]", "")
index = int(index_str)
target_obj = getattr(target_obj, attr)[index]
except ValueError:
except ValueError: # noqa: PERF203
# No index, so just get the attribute
target_obj = getattr(target_obj, part)
except AttributeError:

View File

@ -5,7 +5,7 @@ from pydase.utils.helpers import get_component_class_names
logger = logging.getLogger(__name__)
def warn_if_instance_class_does_not_inherit_from_DataService(__value: object) -> None:
def warn_if_instance_class_does_not_inherit_from_data_service(__value: object) -> None:
base_class_name = __value.__class__.__base__.__name__
module_name = __value.__class__.__module__
@ -18,7 +18,7 @@ def warn_if_instance_class_does_not_inherit_from_DataService(__value: object) ->
"_abc",
]
and base_class_name
not in ["DataService", "list", "Enum"] + get_component_class_names()
not in ["DataService", "list", "Enum", *get_component_class_names()]
and type(__value).__name__ not in ["CallbackManager", "TaskManager", "Quantity"]
):
logger.warning(