implements ruff suggestions

This commit is contained in:
Mose Müller 2023-11-27 17:16:15 +01:00
parent d517bd0489
commit 617eed4d96
2 changed files with 13 additions and 14 deletions

View File

@ -20,7 +20,7 @@ class DefaultFormatter(uvicorn.logging.ColourizedFormatter):
for formatting the output, instead of the plain text message. for formatting the output, instead of the plain text message.
""" """
def formatMessage(self, record: logging.LogRecord) -> str: def formatMessage(self, record: logging.LogRecord) -> str: # noqa: N802
recordcopy = copy(record) recordcopy = copy(record)
levelname = recordcopy.levelname levelname = recordcopy.levelname
seperator = " " * (8 - len(recordcopy.levelname)) seperator = " " * (8 - len(recordcopy.levelname))
@ -74,7 +74,7 @@ def setup_logging(level: Optional[str | int] = None) -> None:
with an option to override the level. By default, in a development environment, the with an option to override the level. By default, in a development environment, the
log level is set to DEBUG, whereas in other environments, it is set to INFO. log level is set to DEBUG, whereas in other environments, it is set to INFO.
Parameters: Args:
level (Optional[str | int]): level (Optional[str | int]):
A specific log level to set for the application. If None, the log level is A specific log level to set for the application. If None, the log level is
determined based on the application's operation mode. Accepts standard log determined based on the application's operation mode. Accepts standard log

View File

@ -28,7 +28,7 @@ class Serializer:
def serialize_object(obj: Any) -> dict[str, Any]: def serialize_object(obj: Any) -> dict[str, Any]:
result: dict[str, Any] = {} result: dict[str, Any] = {}
if isinstance(obj, AbstractDataService): if isinstance(obj, AbstractDataService):
result = Serializer._serialize_DataService(obj) result = Serializer._serialize_data_service(obj)
elif isinstance(obj, list): elif isinstance(obj, list):
result = Serializer._serialize_list(obj) result = Serializer._serialize_list(obj)
@ -38,7 +38,7 @@ class Serializer:
# Special handling for u.Quantity # Special handling for u.Quantity
elif isinstance(obj, u.Quantity): elif isinstance(obj, u.Quantity):
result = Serializer._serialize_Quantity(obj) result = Serializer._serialize_quantity(obj)
# Handling for Enums # Handling for Enums
elif isinstance(obj, Enum): elif isinstance(obj, Enum):
@ -83,7 +83,7 @@ class Serializer:
} }
@staticmethod @staticmethod
def _serialize_Quantity(obj: u.Quantity) -> dict[str, Any]: def _serialize_quantity(obj: u.Quantity) -> dict[str, Any]:
obj_type = "Quantity" obj_type = "Quantity"
readonly = False readonly = False
doc = get_attribute_doc(obj) doc = get_attribute_doc(obj)
@ -154,7 +154,7 @@ class Serializer:
} }
@staticmethod @staticmethod
def _serialize_DataService(obj: AbstractDataService) -> dict[str, Any]: def _serialize_data_service(obj: AbstractDataService) -> dict[str, Any]:
readonly = False readonly = False
doc = get_attribute_doc(obj) doc = get_attribute_doc(obj)
obj_type = type(obj).__name__ obj_type = type(obj).__name__
@ -180,9 +180,7 @@ class Serializer:
# Skip keys that start with "start_" or "stop_" and end with an async # Skip keys that start with "start_" or "stop_" and end with an async
# method name # method name
if (key.startswith("start_") or key.startswith("stop_")) and key.split( if key.startswith(("start_", "stop_")) and key.split("_", 1)[1] in {
"_", 1
)[1] in {
name name
for name, _ in inspect.getmembers( for name, _ in inspect.getmembers(
obj, predicate=inspect.iscoroutinefunction obj, predicate=inspect.iscoroutinefunction
@ -293,6 +291,7 @@ def get_nested_dict_by_path(
def get_next_level_dict_by_key( def get_next_level_dict_by_key(
serialization_dict: dict[str, Any], serialization_dict: dict[str, Any],
attr_name: str, attr_name: str,
*,
allow_append: bool = False, allow_append: bool = False,
) -> dict[str, Any]: ) -> dict[str, Any]:
""" """
@ -366,23 +365,23 @@ def generate_serialized_data_paths(
attribute in the serialized data. attribute in the serialized data.
""" """
paths = [] paths: list[str] = []
for key, value in data.items(): for key, value in data.items():
if value["type"] == "method": if value["type"] == "method":
# ignoring methods # ignoring methods
continue continue
new_path = f"{parent_path}.{key}" if parent_path else key new_path = f"{parent_path}.{key}" if parent_path else key
if isinstance(value["value"], dict) and value["type"] != "Quantity": if isinstance(value["value"], dict) and value["type"] != "Quantity":
paths.extend(generate_serialized_data_paths(value["value"], new_path)) # type: ignore paths.extend(generate_serialized_data_paths(value["value"], new_path))
elif isinstance(value["value"], list): elif isinstance(value["value"], list):
for index, item in enumerate(value["value"]): for index, item in enumerate(value["value"]):
indexed_key_path = f"{new_path}[{index}]" indexed_key_path = f"{new_path}[{index}]"
if isinstance(item["value"], dict): if isinstance(item["value"], dict):
paths.extend( # type: ignore paths.extend(
generate_serialized_data_paths(item["value"], indexed_key_path) generate_serialized_data_paths(item["value"], indexed_key_path)
) )
else: else:
paths.append(indexed_key_path) # type: ignore paths.append(indexed_key_path)
else: else:
paths.append(new_path) # type: ignore paths.append(new_path)
return paths return paths