mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
ref: typehints, enum instead of raw string, abc and other (#1)
Full code coverage with annotations, fixing errors in various linters: ruff, wps, etc. Fixing errors in type checkers: ty, mypy, pyright. Formatting and bringing code to a consistent style, applying best practices in various aspects.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
__all__ = ["Response", "Status"]
|
||||
__all__ = ["Response", "ResponseStatus"]
|
||||
|
||||
|
||||
from argenta.response.entity import Response
|
||||
from argenta.response.status import Status
|
||||
from argenta.response.status import ResponseStatus
|
||||
|
||||
@@ -1,29 +1,23 @@
|
||||
from argenta.response.status import Status
|
||||
from argenta.command.flag.flags import (
|
||||
ValidInputFlags,
|
||||
UndefinedInputFlags,
|
||||
InvalidValueInputFlags,
|
||||
)
|
||||
from typing import Literal
|
||||
from argenta.command.flag.flags.models import InputFlags
|
||||
from argenta.response.status import ResponseStatus
|
||||
|
||||
|
||||
EMPTY_INPUT_FLAGS: InputFlags = InputFlags()
|
||||
|
||||
|
||||
class Response:
|
||||
__slots__ = ("status", "valid_flags", "undefined_flags", "invalid_value_flags")
|
||||
__slots__: tuple[Literal['status', 'input_flags'], ...] = ("status", "input_flags")
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
status: Status | None = None,
|
||||
valid_flags: ValidInputFlags = ValidInputFlags(),
|
||||
undefined_flags: UndefinedInputFlags = UndefinedInputFlags(),
|
||||
invalid_value_flags: InvalidValueInputFlags = InvalidValueInputFlags(),
|
||||
status: ResponseStatus,
|
||||
input_flags: InputFlags = EMPTY_INPUT_FLAGS,
|
||||
):
|
||||
"""
|
||||
Public. The entity of the user input sent to the handler
|
||||
:param status: the status of the response
|
||||
:param valid_flags: valid input flags
|
||||
:param undefined_flags: undefined input flags
|
||||
:param invalid_value_flags: input flags with invalid values
|
||||
:param input_flags: all input flags
|
||||
"""
|
||||
self.status = status
|
||||
self.valid_flags = valid_flags
|
||||
self.undefined_flags = undefined_flags
|
||||
self.invalid_value_flags = invalid_value_flags
|
||||
self.status: ResponseStatus = status
|
||||
self.input_flags: InputFlags = input_flags
|
||||
|
||||
@@ -1,8 +1,19 @@
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Status(Enum):
|
||||
class ResponseStatus(Enum):
|
||||
ALL_FLAGS_VALID = "ALL_FLAGS_VALID"
|
||||
UNDEFINED_FLAGS = "UNDEFINED_FLAGS"
|
||||
INVALID_VALUE_FLAGS = "INVALID_VALUE_FLAGS"
|
||||
UNDEFINED_AND_INVALID_FLAGS = "UNDEFINED_AND_INVALID_FLAGS"
|
||||
|
||||
@classmethod
|
||||
def from_flags(cls, *, has_invalid_value_flags: bool, has_undefined_flags: bool) -> 'ResponseStatus':
|
||||
key = (has_invalid_value_flags, has_undefined_flags)
|
||||
status_map: dict[tuple[bool, bool], ResponseStatus] = {
|
||||
(True, True): cls.UNDEFINED_AND_INVALID_FLAGS,
|
||||
(True, False): cls.INVALID_VALUE_FLAGS,
|
||||
(False, True): cls.UNDEFINED_FLAGS,
|
||||
(False, False): cls.ALL_FLAGS_VALID,
|
||||
}
|
||||
return status_map[key]
|
||||
|
||||
Reference in New Issue
Block a user